我想知道在使用sequelize数据库适配器(或任何其他适配器)时如何从服务中删除一些服务方法(端点)
// Initializes the `society` service on path `/society`
const createService = require('feathers-sequelize');
const createModel = require('../../models/society.model');
const hooks = require('./society.hooks');
module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
name: 'society',
Model,
paginate
};
// Initialize our service with any options it requires
app.use('/societies', createService(options));
// Get our initialized service so that we can register hooks and filters
const service = app.service('societies');
service.hooks(hooks);
};
此处,所有服务方式:get,patch,post,remove
均可用 - 我希望只有get
和find
一种方法是使用钩子停止请求,但这是一种肮脏的方式。
答案 0 :(得分:1)
Hooks是Feathers如何控制这样的事情。您可以通过检查是否设置了params.provider
来阻止外部访问:
const { Forbidden } = require('@feathersjs/errors');
const disable = context => {
if(context.params.provider) {
throw new Forbidden('You can not do this');
}
};
app.service('societies').hooks({
before: {
get: disable,
patch: disable,
update: disable,
remove: disable
}
})