我想基于URL中提到的id属性获取用户数据:(/user/488/all
)使用FratherJS框架
var mongooseService = require('feathers-mongoose');
...
app.use('user/:id/all', mongooseService({
name: 'agency',
Model: require('models/user') //user.id is the ID of user model
}));
...
我不想使用此网址:/user/488
答案 0 :(得分:1)
Feathers标准网址是专门围绕REST网址最佳做法构建的,所以尽管并非不可能,但如果有充分的理由,我只会打破它。要与现有客户端兼容,您可以使用custom service:
创建别名const mongooseService = require('feathers-mongoose');
app.use('/users', mongooseService({
name: 'agency',
Model: require('models/user') //user.id is the ID of user model
}));
class UserAliases {
async find(params) {
const { id } = params.route;
return this.app.service('users').get(id, params);
}
setup(app) {
this.app = app;
}
}
app.use('/user/:id/all', new UserAliases());