actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
34 lines (33 loc) • 1.15 kB
TypeScript
export declare namespace action {
/**
* var middleware = {
* name: 'userId checker',
* global: false,
* priority: 1000,
* preProcessor: async (data) => {
* if(!data.params.userId){
* throw new Error('All actions require a userId')
* }
* },
* postProcessor: async (data) => {
* if(data.thing.stuff == false){ data.toRender = false }
* }
*}
*/
interface ActionMiddleware {
/**Unique name for the middleware. */
name: string;
/**Is this middleware applied to all actions? */
global: boolean;
/**Module load order. Defaults to `api.config.general.defaultMiddlewarePriority`. */
priority?: number;
/**Called before the action runs. Has access to all params, before sanitization. Can modify the data object for use in actions. */
preProcessor?: Function;
/**Called after the action runs. */
postProcessor?: Function;
}
/**
* Add a middleware component available to pre or post-process actions.
*/
function addMiddleware(data: ActionMiddleware): void;
}