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
}
});
Get the Fastify app instance.
const app = actions.gasket.getFastifyApp();
Each Gasket creates a single shared Fastify instance, ensuring consistent access to the same app instance wherever it's needed.
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.