Feathersjs sequelize 数据库适配器服务方法
Featherjs sequelize database adapter service methods
我想知道如何在使用 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
一种方法是使用挂钩停止请求,但这是一种肮脏的方法。
钩子是 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
}
})
我想知道如何在使用 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
一种方法是使用挂钩停止请求,但这是一种肮脏的方法。
钩子是 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
}
})