express-service-bootstrap
Advanced tools
Comparing version 0.13.0 to 0.14.0
{ | ||
"name": "express-service-bootstrap", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "This is a convenience package for starting a express API with security, health checks, process exits etc.", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -38,3 +38,16 @@ import bodyParser from "body-parser"; | ||
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; | ||
} |
@@ -70,2 +70,8 @@ "use strict"; | ||
} | ||
/** | ||
* 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, hostPath = '/api-docs') { | ||
@@ -76,4 +82,17 @@ const swaggerRouter = this.customConstructor.createInstanceWithoutConstructor(express_1.Router); | ||
} | ||
/** | ||
* 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, object) { | ||
const middleware = (req, res, next) => { | ||
req[requestPropertyName] = object; | ||
next(); | ||
}; | ||
return this.customConstructor.createInstanceWithoutConstructor(() => middleware); | ||
} | ||
} | ||
exports.Convenience = Convenience; | ||
//# sourceMappingURL=convenience.js.map |
@@ -10,3 +10,3 @@ import { ApplicationShutdownStatus, ApplicationStartupStatus, ApplicationStatus } from './enum-application-life-cycle-status'; | ||
import { EnvironmentVariables } from './environment-variables'; | ||
import { IRouter } from 'express'; | ||
export { ApplicationStatus, ApplicationShutdownStatus, ApplicationStartupStatus, ApplicationBuilder, BootstrapConstructor, DisposableSingletonContainer, IProbeResult, NullProbe, IProbe, ApplicationBuilderMiddleware, ApplicationTypes, Convenience, ApplicationRouter, HostingPath, EnvironmentVariables, IRouter }; | ||
import { IRouter, Request, Response } from 'express'; | ||
export { ApplicationStatus, ApplicationShutdownStatus, ApplicationStartupStatus, ApplicationBuilder, BootstrapConstructor, DisposableSingletonContainer, IProbeResult, NullProbe, IProbe, ApplicationBuilderMiddleware, ApplicationTypes, Convenience, ApplicationRouter, HostingPath, EnvironmentVariables, IRouter, Request, Response, }; |
{ | ||
"name": "express-service-bootstrap", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "This is a convenience package for starting a express API with security, health checks, process exits etc.", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -50,6 +50,7 @@ # express-service-bootstrap | ||
//Register Routes,Middleware,etc | ||
DIContainer.registerInstance("msg", { message: "Hello from DI" }); //Simulate things stored in DI container | ||
rootRouter | ||
.get("/", (req, res) => { | ||
res.send("Hello World"); | ||
res.send(req.DIProp.fetchInstance("msg").message); | ||
}) | ||
@@ -64,6 +65,7 @@ .get("/error", (req, res) => { | ||
.overrideHealthPort(8081) //override the default health port 8081(Default 5678) | ||
.registerApplicationHandler(utilities.helmetMiddleware(), "*", 0, ApplicationTypes.Both) //register helmet middleware for both application and health | ||
.registerApplicationHandler(utilities.bodyParserURLEncodingMiddleware(), "*", 1, ApplicationTypes.Main) //register body parser url middleware for application | ||
.registerApplicationHandler(utilities.bodyParserJSONEncodingMiddleware({ limit: '50M' }), "*", 2, ApplicationTypes.Main) //register body parser json middleware for application | ||
.registerApplicationHandler(utilities.helmetMiddleware(), "*", 1, ApplicationTypes.Both) //register helmet middleware for both application and health | ||
.registerApplicationHandler(utilities.bodyParserURLEncodingMiddleware(), "*", 2, ApplicationTypes.Main) //register body parser url middleware for application | ||
.registerApplicationHandler(utilities.bodyParserJSONEncodingMiddleware({ limit: '50M' }), "*", 3, ApplicationTypes.Main) //register body parser json middleware for application | ||
.registerApplicationHandler(apiDocs.router, apiDocs.hostingPath, 3, ApplicationTypes.Main) //register api docs | ||
.registerApplicationHandler(utilities.injectInRequestMiddleware("DIProp", DIContainer), "*", 4, ApplicationTypes.Main) //register DI container middleware | ||
.overrideCatchAllErrorResponseTransformer((req, error) => ({ //override the default catch all error response transformer | ||
@@ -70,0 +72,0 @@ path: req.path, |
Sorry, the diff of this file is not supported yet
106752
1243
108