@maon/middlewares
v0.3.1
Published
All the required middlewares for a wasc express project
Downloads
418
Readme
Middlewares
Overview
Middlewares is a simple wrapper around the required middlewares for an express app at maon.
Usage
Just like above:
import middlewares from '@maon/middlewares';
import express from 'express';
const app = express();
app.use(middlewares());
Import the module and use it. It works with CJS require
as well.
Included packages
- Pino
- Helmet
- BodyParser with configuration for json and urlencoded encoding
- Cors
- ExpressValidator
- ServiceVersion
Configuration
All the included modules are imported with standard options but you can customize them by passing in an object
import middlewares from '@maon/middlewares';
import express from 'express';
const app = express();
app.use(middlewares({
cors: {
origin: 'http://example.com,
},
}));
All configuration options in the documentations of the modules are available. If you want to disable a certain module, just pass in false as an option:
middlewares({
cors: false,
});
The configurations are accessible via the names:
pino
helmet
validator
bodyParserJson
bodyParserUrl
serviceVersion
cors
Logger
To use the integrated logging function with the included request object write the following call:
app.get('/', (request, response) => {
try {
// Some working
} catch (error) {
request.log.error(error);
}
});