Adds Fastify to your application.
npm i @gasket/plugin-fastify
Update your gasket
file plugin configuration:
// gasket.js
+ import pluginFastify from '@gasket/plugin-fastify';
export default makeGasket({
plugins: [
+ pluginFastify
]
});
All the configurations for the plugin are added under fastify
in the config:
compression
: true by default. Can be set to false if applying compression differently.trustProxy
: Enable trust proxy option, see Fastify documentation for possible valuesdisableRequestLogging
: Turn off request logging, true by default
export default makeGasket({
plugins: [
pluginFastify
],
fastify: {
compression: false,
routes: 'api/*.js',
excludedRoutesRegex: /^(?!\/_next\/)/,
trustProxy: true
}
});
Routes can be defined in a in-app plugin in the plugins
directory. The plugin will hook the fastify
lifecycle to add the routes to the fastify app.
// plugins/routes-plugin.js
export default {
name: 'routes-plugin',
hooks: {
fastify: async function (gasket, app) {
app.get('/hello', (req, res) => {
res.send('Hello World!');
});
}
}
};
Executed after the middleware
event for when you need full control over
the fastify
instance.
export default {
name: 'sample-plugin',
hooks: {
/**
* Update Fastify app instance
*
* @param {Gasket} gasket The Gasket API
* @param {Fastify} fastify Fastify app instance
* @returns {function|function[]} middleware(s)
*/
fastify: async function (gasket, fastify) {
}
}
};
Executed after the fastify
event. All middleware functions returned from this
hook will be applied to Fastify.
export default {
name: 'sample-plugin',
hooks: {
/**
* Add Fastify error middlewares
*
* @param {Gasket} gasket The Gasket API
* @returns {function|function[]} error middleware(s)
*/
errorMiddleware: function (gasket) {
}
}
};
This plugins hooks the createServers lifecycles from @gasket/plugin-https.