我正在尝试使用SailsJS 0.10.1与现有的后端API进行通信,并使用该内容呈现页面。我遇到了让sails-rest适配器正常工作的问题,我可以在connections.js中定义连接并对资源进行硬编码然后找到工作。我想要的是将模型名称作为资源,或者能够在模型级别的config参数中指定资源。
/**
* Product.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
};
index: function(req, res ,next){
var options = {
limit: req.param('limit') || undefined
};
Product.find(options, function(err, product){
if (product === 'undefined') return res.notFound();
if (err) return next(err);
res.view('products/index', { products: product });
});
}
rest: {
adapter: 'sails-rest',
host: 'localhost',
port: 3000, // api port
protocol: 'http', // HTTP protocol (http | https)
pathname: null, // base api path
resource: null, // resource path to use (overrides model name)
action: null, // action to use for the given resource ([resource]/run)
query: {}, // query parameters to provide with all GET requests
methods: { // overrides default HTTP methods used for each CRUD action
create: 'post',
find: 'get',
update: 'put',
destroy: 'del'
}
}
答案 0 :(得分:1)
我会在https://github.com/zohararad/sails-rest/pull/21中执行此操作,但最后的网址是http://localhost/products,因为我在更改中使用了下划线变形。