我有
epilogue.resource({
model: db.Question,
endpoints: ['/api/questions', '/api/questions/:id'],
associations: true
});
所以,当我点击/api/questions
时,我会收回与资源的所有关联。在某些情况下,我是否可以通过某些内容来获取关联?或者我应该创建一个新的端点:
epilogue.resource({
model: db.Question,
endpoints: ['/api/questions2', '/api/questions2/:id']
});
答案 0 :(得分:1)
一种方法是使用里程碑,您可以在某些情况下为列表和读取行为定义里程碑,您可以访问req对象,以便相应地进行更改
https://github.com/dchester/epilogue#customize-behavior
以下是列表调用修改的示例
// my-middleware.js
module.exports = {
list: {
write: {
before: function(req, res, context) {
// modify data before writing list data
return context.continue;
},
action: function(req, res, context) {
// change behavior of actually writing the data
return context.continue;
},
after: function(req, res, context) {
// set some sort of flag after writing list data
return context.continue;
}
}
}
};
// my-app.js
var epilogue = require('epilogue'),
restMiddleware = require('my-middleware');
epilogue.initialize({
app: app,
sequelize: sequelize
});
var userResource = epilogue.resource({
model: User,
endpoints: ['/users', '/users/:id']
});
userResource.use(restMiddleware);