express-service-bootstrap
Version:
This is a convenience package for starting a express API with security, health checks, process exits etc.
60 lines (59 loc) • 3.44 kB
TypeScript
import bodyParser from "body-parser";
import { BootstrapConstructor } from "./bootstrap-constructor";
import { ApplicationBuilderMiddleware } from "./application-builder";
import { HelmetOptions } from "helmet";
import { IRouter } from "express";
import { CompressionOptions } from "compression";
export type ApplicationRouter = {
hostingPath: string;
router: IRouter;
};
/**
* A convenience class that provides a way to create middleware instances without the need to manually create them.
*/
export declare class Convenience {
private readonly customConstructor;
/**
* Creates a new instance of the convenience class.
* @param DIConstructor The dependency injection constructor to use to create instances of middleware.
*/
constructor(customConstructor?: BootstrapConstructor);
/**
* Creates a new instance of the body parser middleware for url encoding.
* @param urlEncodingOptions The options to use for the url encoding middleware.
* @returns {ApplicationBuilderMiddleware} A new instance of the body parser middleware for url encoding.
*/
bodyParserURLEncodingMiddleware(urlEncodingOptions?: bodyParser.OptionsUrlencoded): ApplicationBuilderMiddleware;
/**
* Creates a new instance of the body parser middleware for JSON encoding.
* @param jsonOptions The options to use for the JSON encoding middleware.
* @returns {ApplicationBuilderMiddleware} A new instance of the body parser middleware for JSON encoding.
*/
bodyParserJSONEncodingMiddleware(jsonOptions?: bodyParser.OptionsJson): ApplicationBuilderMiddleware;
/**
* Creates a new instance of the body parser middleware for raw encoding.
* @param helmetOptions The options to use for the raw encoding middleware.
* @returns {ApplicationBuilderMiddleware} A new instance of the helmet middleware.
*/
helmetMiddleware(helmetOptions?: Readonly<HelmetOptions>): (req: import("http").IncomingMessage, res: import("http").ServerResponse, next: (err?: unknown) => void) => void;
/**
* Creates a new instance of the swagger API documentation middleware.
* @param swaggerDocument The swagger document to use for the API documentation, typically a json object.
* @param hostPath The host path to use for the swagger API documentation.
* @returns {ApplicationRouter} A new instance of the swagger API documentation middleware.
*/
swaggerAPIDocs(swaggerDocument: any, hostPath?: string): ApplicationRouter;
/**
* Injects a specified object into the request under a given property name.
* @param requestPropertyName - The name of the property to add to the request object.
* @param object - The object to inject into the request.
* @returns {ApplicationBuilderMiddleware} A middleware function that injects the object into the request.
*/
injectInRequestMiddleware(requestPropertyName: string, object: any): ApplicationBuilderMiddleware;
/**
* Creates a new instance of the compression middleware.
* @param compressionOptions The options to use for the compression middleware.
* @returns {ApplicationBuilderMiddleware} A new instance of the compression middleware.
*/
compressionMiddleware(compressionOptions?: CompressionOptions): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
}