@gasket/plugin-express
Adds Express to your application.
Guides
Installation
npm i @gasket/plugin-express
Update your gasket
file plugin configuration:
// gasket.js
+ import pluginExpress from '@gasket/plugin-express';
export default makeGasket({
plugins: [
+ pluginExpress
]
});
Configuration
All the configurations for the plugin are added under express
in the config:
Example configuration
export default makeGasket({
plugins: [
pluginExpress
],
express: {
compression: false,
trustProxy: true
}
});
Route Definition
Routes can be defined in a in-app plugin in the plugins
directory. The plugin will hook the express
lifecycle to add the routes to the express app.
export default {
name: 'routes-plugin',
hooks: {
express: async function (gasket, app) {
app.get('/hello', (req, res) => {
res.send('Hello World!');
});
}
}
};
Lifecycles
express
Executed after the middleware
event for when you need full control over
the express
instance.
export default {
name: 'sample-plugin',
hooks: {
express: async function (gasket, express) {
}
}
};
errorMiddleware
Executed after the express
event. All middleware functions returned from this
hook will be applied to Express.
export default {
name: 'sample-plugin',
hooks: {
errorMiddleware: function (gasket) {
}
}
};
How it works
This plugins hooks the createServers lifecycles from @gasket/plugin-https.
License
MIT