Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (req, res, next) {
const { query } = req;
const route = omit(req.params, '__feathersId');
res.setHeader('Allow', allowedMethods.join(','));
// Check if the method exists on the service at all. Send 405 (Method not allowed) if not
if (typeof service[method] !== 'function') {
debug(`Method '${method}' not allowed on '${req.url}'`);
res.status(statusCodes.methodNotAllowed);
return next(new errors.MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`));
}
// Grab the service parameters. Use req.feathers
// and set the query to req.query merged with req.params
const params = Object.assign({
query, route
}, req.feathers);
Object.defineProperty(params, '__returnHook', {
value: true
});
const args = getArgs(req, params);
debug(`REST handler calling \`${method}\` from \`${req.url}\``);
module.exports = function (predicate) {
if (typeof predicate !== 'function') {
throw new errors.MethodNotAllowed('Expected function as param. (isNot)');
}
return context => {
const result = predicate(context); // Should we pass a clone? (safety vs performance)
if (!result || typeof result.then !== 'function') {
return !result;
}
return result.then(result1 => !result1);
};
};
const _run = () => {
const lookup = app.lookup(path);
// No valid service was found, return a 404
// just like a REST route would
if (lookup === null) {
return Promise.reject(new errors.NotFound(`Service '${path}' not found`));
}
const { service, params: route = {} } = lookup;
// Only service methods are allowed
// @ts-ignore
if (paramsPositions[method] === undefined || typeof service[method] !== 'function') {
return Promise.reject(new errors.MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`));
}
const position = paramsPositions[method];
const query = methodArgs[position] || {};
// `params` have to be re-mapped to the query
// and added with the route
const params = Object.assign({ query, route, connection }, connection);
methodArgs[position] = params;
// @ts-ignore
return service[method](...methodArgs, true);
};
patch (id: NullableId, data: Partial, params?: Params): Promise {
if (id === null && !this.allowsMulti('patch')) {
return Promise.reject(new MethodNotAllowed(`Can not patch multiple entries`));
}
return callMethod(this, '_patch', id, data, params);
}
async update(id, data, params) {
throw new errors.MethodNotAllowed('can not update on docs service')
}
break;
case 402:
feathersError = new errors.PaymentError(error);
break;
case 403:
feathersError = new errors.Forbidden(error);
break;
case 404:
feathersError = new errors.NotFound(error);
break;
case 405:
feathersError = new errors.MethodNotAllowed(error);
break;
case 406:
feathersError = new errors.NotAcceptable(error);
break;
case 408:
feathersError = new errors.Timeout(error);
break;
case 409:
feathersError = new errors.Conflict(error);
break;
case 422:
feathersError = new errors.Unprocessable(error);
remove (id: NullableId, params?: Params): Promise {
if (id === null && !this.allowsMulti('remove')) {
return Promise.reject(new MethodNotAllowed(`Can not remove multiple entries`));
}
return callMethod(this, '_remove', id, params);
}
}
module.exports = function (...providers) {
if (!providers.length) {
throw new errors.MethodNotAllowed('Calling iff() predicate incorrectly. (isProvider)');
}
return context => {
const hookProvider = (context.params || {}).provider;
return providers.some(provider => provider === hookProvider ||
(provider === 'server' && !hookProvider) ||
(provider === 'external' && hookProvider)
);
};
};
create (data: Partial | Array>, params?: Params): Promise {
if (Array.isArray(data) && !this.allowsMulti('create')) {
return Promise.reject(new MethodNotAllowed(`Can not create multiple entries`));
}
return callMethod(this, '_create', data, params);
}
raw (method, params = {}) {
if (typeof method === 'undefined') {
return Promise
.reject(new errors.MethodNotAllowed('params.method must be defined.'))
.catch(errorHandler);
}
return this.core.raw(this, method, params)
.catch(errorHandler);
}
}