unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
48 lines (47 loc) • 2.02 kB
TypeScript
import { IRouter, Request, Response, RequestHandler } from 'express';
import { IUnleashConfig } from '../types/option';
interface IRequestHandler<P = any, ResBody = any, ReqBody = any, ReqQuery = any> {
(req: Request<P, ResBody, ReqBody, ReqQuery>, res: Response<ResBody>): Promise<void> | void;
}
interface IRouteOptionsBase {
path: string;
permission: string;
middleware?: RequestHandler[];
handler: IRequestHandler;
acceptedContentTypes?: string[];
}
interface IRouteOptionsGet extends IRouteOptionsBase {
method: 'get';
}
interface IRouteOptionsNonGet extends IRouteOptionsBase {
method: 'post' | 'put' | 'patch' | 'delete';
acceptAnyContentType?: boolean;
}
declare type IRouteOptions = IRouteOptionsNonGet | IRouteOptionsGet;
/**
* Base class for Controllers to standardize binding to express Router.
*
* This class will take care of the following:
* - try/catch inside RequestHandler
* - await if the RequestHandler returns a promise.
* - access control
*/
export default class Controller {
private ownLogger;
app: IRouter;
config: IUnleashConfig;
constructor(config: IUnleashConfig);
private useRouteErrorHandler;
private useContentTypeMiddleware;
route(options: IRouteOptions): void;
get(path: string, handler: IRequestHandler, permission?: string): void;
post(path: string, handler: IRequestHandler, permission: string, ...acceptedContentTypes: string[]): void;
put(path: string, handler: IRequestHandler, permission: string, ...acceptedContentTypes: string[]): void;
patch(path: string, handler: IRequestHandler, permission: string, ...acceptedContentTypes: string[]): void;
delete(path: string, handler: IRequestHandler, permission: string): void;
fileupload(path: string, filehandler: IRequestHandler, handler: Function, permission: string): void;
use(path: string, router: IRouter): void;
useWithMiddleware(path: string, router: IRouter, middleware: any): void;
get router(): any;
}
export {};