import { CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext, } from '@midwayjs/core'; import { Application as ExpressApplication, NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse, } from 'express'; import { ListenOptions } from 'net'; type Request = IMidwayContext; export type Response = ExpressResponse; export type NextFunction = ExpressNextFunction; export interface Context extends Request { /** * API version extracted from request */ apiVersion?: string; /** * Original path before version processing */ originalPath?: string; } /** * @deprecated use Context */ export type IMidwayExpressRequest = Context; /** * @deprecated use Context */ export type IMidwayExpressContext = Context; export type IMidwayExpressMiddleware = IMiddleware< Context, ExpressResponse, ExpressNextFunction >; export interface IMidwayExpressApplication extends IMidwayApplication< Context, ExpressApplication > { /** * mount router and middleware * @param routerPath * @param middleware */ useMiddleware( routerPath: string, ...middleware: FunctionMiddleware[] ): void; /** * add global middleware to app * @param middleware */ useMiddleware( middleware: CommonMiddlewareUnion ): void; /** * get global middleware */ getMiddleware(): ContextMiddlewareManager< Context, Response, NextFunction >; } export interface IMidwayExpressConfigurationOptions extends IConfigurationOptions { /** * session or cookie secret key */ keys?: string | string[]; /** * application http port */ port?: number; /** * application hostname, 127.0.0.1 as default */ hostname?: string; /** * https key */ key?: string | Buffer | Array; /** * https cert */ cert?: string | Buffer | Array; /** * https ca */ ca?: string | Buffer | Array; /** * http2 support */ http2?: boolean; /** * http global prefix */ globalPrefix?: string; /** * https/https/http2 server options */ serverOptions?: Record; /** * listen options */ listenOptions?: ListenOptions; /** * API versioning configuration */ versioning?: { /** * Enable versioning */ enabled: boolean; /** * Versioning type */ type?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM'; /** * Default version if none is specified */ defaultVersion?: string; /** * Version prefix for URI versioning (default: 'v') */ prefix?: string; /** * Header name for HEADER versioning (default: 'x-api-version') */ header?: string; /** * Media type parameter name for MEDIA_TYPE versioning (default: 'version') */ mediaTypeParam?: string; /** * Custom version extraction function */ extractVersionFn?: (ctx: Context) => string | undefined; }; } export type Application = IMidwayExpressApplication;