🚀 Feature Proposal
Expose the options used to create the fastify server in a way that is accessible to plugins.
Motivation
In some cases it might be necessary to register routes differently, for example if ignoreTrailingSlash is enabled it is impossible to register separate routes for /dir vs /dir/.
Example
fastify/fastify-static#93 adds an option to send a 301 redirect when a request for a directory without the trailing slash is received. This option currently cannot be combined with wildcard: false if ignoreTrailingSlash is enabled on the server.
const fastify = require('fastify')({
ignoreTrailingSlash: true
})
fastify.register(async (instance, opts) => {
if (opts.initialConf.ignoreTrailingSlash) {
// This registers `/dir` and `/dir/` so a shared handler needs to
// determine which was requested and call handleDir or handleDirSlash.
instance.get('/dir', handleDirOrDirSlash)
} else {
instance.get('/dir', handleDir)
instance.get('/dir/', handleDirSlash)
}
})
🚀 Feature Proposal
Expose the options used to create the fastify server in a way that is accessible to plugins.
Motivation
In some cases it might be necessary to register routes differently, for example if
ignoreTrailingSlashis enabled it is impossible to register separate routes for/dirvs/dir/.Example
fastify/fastify-static#93 adds an option to send a 301 redirect when a request for a directory without the trailing slash is received. This option currently cannot be combined with
wildcard: falseifignoreTrailingSlashis enabled on the server.