UNPKG

plumier

Version:

Delightful Node.js Rest Framework

93 lines (92 loc) 3.11 kB
/// <reference types="koa__cors" /> import Cors from "@koa/cors"; import { ActionResult, Class, CustomMiddleware, DefaultFacility, DependencyResolver, Invocation, PlumierApplication } from "@plumier/core"; import { Context } from "koa"; import BodyParser from "koa-body"; export interface WebApiFacilityOption { bodyParser?: BodyParser.IKoaBodyOptions; cors?: Cors.Options | boolean; /** * Trust X-Forwarded-For header */ trustProxyHeader?: boolean; /** * Redirect all http request into https, enable trustProxyHeader option when using proxy server */ forceHttps?: boolean; /** * Set custom dependency resolver for dependency injection */ dependencyResolver?: DependencyResolver; /** * Root path of the endpoint generated, for example /api/v1 */ rootPath?: string; /** * Controllers or controller path */ controller?: string | string[] | Class | Class[]; /** * Transform nested directories as route path, disabled when glob path specified on controller configuration, default true */ directoryAsPath?: boolean; } /** * Preset configuration for building rest. This facility contains: * * parameter binder * * body parser: koa-body * * cors: @koa/cors */ export declare class WebApiFacility extends DefaultFacility { private opt?; constructor(opt?: WebApiFacilityOption | undefined); generateRoutes(app: Readonly<PlumierApplication>): Promise<import("@plumier/core").RouteMetadata[]>; setup(app: Readonly<PlumierApplication>): void; } /** * Preset configuration for building restful style api. This facility contains: * * parameter binder * * body parser: koa-body * * cors: @koa/cors * * default response status: { get: 200, post: 201, put: 204, delete: 204 } */ export declare class RestfulApiFacility extends WebApiFacility { setup(app: Readonly<PlumierApplication>): void; } export declare class ForceHttpsMiddleware implements CustomMiddleware { execute(i: Readonly<Invocation<Context>>): Promise<ActionResult>; } export declare class LoggerFacility extends DefaultFacility { setup(app: Readonly<PlumierApplication>): void; } export interface ControllerFacilityOption { /** * Define group of route generated, this will be used to categorized routes in Route Analysis and Swagger (separate swagger endpoint for each group) */ group?: string; /** * Root path of the endpoint generated, for example /api/v1 */ rootPath?: string; /** * Controllers or controller path */ controller: string | string[] | Class | Class[]; /** * Transform nested directories as route path, disabled when glob path specified on controller configuration, default true */ directoryAsPath?: boolean; } export declare class ControllerFacility extends DefaultFacility { private option; constructor(option: ControllerFacilityOption); setup(app: Readonly<PlumierApplication>): void; generateRoutes(app: Readonly<PlumierApplication>): Promise<import("@plumier/core").RouteMetadata[]>; }