Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not found handler not called when used as plugin with prefix #334

Closed
2 tasks done
vlatkoodrljin opened this issue Aug 16, 2022 · 0 comments · Fixed by fastify/fastify#4203
Closed
2 tasks done

Not found handler not called when used as plugin with prefix #334

vlatkoodrljin opened this issue Aug 16, 2022 · 0 comments · Fixed by fastify/fastify#4203

Comments

@vlatkoodrljin
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.4.0

Plugin version

6.5.0

Node.js version

16.14.2

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Description

I need to serve static files from several sibling directories, every directory on different route.

Wrapped this plugin in a plugin with prefix which seems valid to me.

When path is correct everything works ok.

Cannot use 404 handler properly, and that makes everything confusing and pretty unreliable.

If path is not correct not found handler is not called and following error is occurred:

TypeError: Cannot read properties of undefined (reading 'length') at next (fastify-static-not-found-bug/node_modules/fastify/lib/hooks.js:212:25) at onSendHookRunner (fastify-static-not-found-bug/node_modules/fastify/lib/hooks.js:241:3) at preserializeHook (fastify-static-not-found-bug/node_modules/fastify/lib/reply.js:454:5) at _Reply.Reply.send (fastify-static-not-found-bug/node_modules/fastify/lib/reply.js:182:7) at fastify-static-not-found-bug/node_modules/fastify/lib/wrapThenable.js:25:15

Not sure if this is related with encapsulation in some way, but I think that according to the docs everything is valid.

Steps to Reproduce

https://github.com/vlatkoodrljin/fastify-static-not-found-bug

yarn install

node index

Visit for example: http://localhost:3000/public/js/temp2.js and observe returned error

Expected Behavior

Calling of proper not found handler defined in specific plugin context.

@vlatkoodrljin vlatkoodrljin changed the title Not found handler bug when used as plugin with prefix Not found handler not called when used as plugin with prefix Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant