-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional trailing "/" after prefix #122
Comments
Try setting Fastify's const fastify = require('fastify')({
ignoreTrailingSlash: true
}) |
This won't work in my use case since, I am not using fastify directly, rather building an object and passing it to a module that creates fastify. Can the same flag be implemented in fastify-static? const fastifyStatic = require('fastify-static');
async function registerRoutes(app) {
app.register(fastifyStatic, {
prefix: '/docs',
root: path.join(__dirname, '../docs')
});
app.get('/foo', async (req, res)
}
// external module takes function to build routes
buildRoutes(registerRoutes); |
Unfortunately that option is specific to fastify router, so you cannot set it on the module itself. Lines 125 to 130 in e1ad93b
prefix: false ?
Would you like to send a PR for a different option that implement what you need? |
So, I tried the option ignoreTrailingSlash: true and it still appends trailing slash :sad However, if I modify Line 110 in e1ad93b
to const prefix = opts.prefix[opts.prefix.length - 1] === '/' ? opts.prefix : opts.prefix; My static content is served at /docs without trailing slash, just like I need. I can make a PR to make it optional with the flag. |
That'd be rad, thanks! |
Released in 2.7.0 Thank you for your contribution! |
馃悰 Bug Report
I am trying to serve static content over /docs prefix, but being redirected to /docs/ since trailing slash is appended by default.
To Reproduce
Register route with prefix that does not have trailing /, start application, assuming everything done right static content in docs folder will be available at /docs/ instead of /docs.
Expected behavior
Static content be available at /docs instead of /docs/.
Your Environment
The text was updated successfully, but these errors were encountered: