Response formater midleware for express
Extract requested file type and parse data
-
Add extract() as midleware
-
Add postfix .:ext? to the route
-
Use render() for response
-
Try to open your route at browser with adding .json, .xml or .html extension at the end or by changing requested mime type
const extensions = require('mio-extensions');
... INIT express ...
app.use(extensions.extract);
... Update Routes ...
app.get('/error/:code?.:ext?')...
... Write Route function
extensions.render(req, res, {
status: errorCode,
template: './pathToYourTemplate/Vash.PuG',
data: {
code: errorCode,
error: errorMessage,
message: errorHint
}
});
This library just wrap up your logic, so it's agnostic to your template engine.
All options except data are optional