@wasc/middlewares
v1.3.1
Published
All essential middlewares for a Wasc express project
Downloads
3
Readme
Middlewares
Overview
Middlewares is a simple wrapper around the required middlewares for an express app at Wasc.
Usage
Just like above:
import middlewares from '@wasc/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
- ServiceVersion
Configuration
All the included modules are imported with standard options but you can customize them by passing in an object
import middlewares from '@wasc/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);
}
});
This was made by Wasc