Adds Fastify to your application.
gasket create <app-name> --plugins @gasket/plugin-fastify
npm i @gasket/plugin-fastify
Modify plugins section of your gasket.config.js:
module.exports = {
plugins: {
add: [
+ '@gasket/plugin-fastify'
]
}
}All the configurations for the plugin are added under fastify in the config:
compression: true by default. Can to set to false if applying compression differently.excludedRoutesRegex: Regex of the routes to exclude by Fastify.
module.exports = {
plugins: {
add: ['@gasket/fastify']
},
fastify: {
compression: false,
excludedRoutesRegex: /^(?!\/_next\/)/
}
}Executed when the fastify server has been created, it will apply all returned
functions as middleware.
module.exports = {
hooks: {
/**
* Add Fastify middleware
*
* @param {Gasket} gasket The Gasket API
* @param {Fastify} app - Fastify app instance
* @returns {function|function[]} middleware(s)
*/
middleware: function (gasket, app) {
return require('x-xss-protection')();
}
}
}You may also return an Array to inject more than one middleware.
Executed after the middleware event for when you need full control over
the fastify instance.
module.exports = {
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.
module.exports = {
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.