fastify/fastify-websocket

Fastify 3.10 breaks prefixed plugins

Skn0tt opened this issue ยท 2 comments

๐Ÿ› Bug Report

Fastify 3.10, together with the use of prefixes, breaks fastify-websocket.

fastify.register(
  (fastify, opts, done) => {
    fastify.get("/", { websocket: true }, (connection, req) => {
      connection.socket.send("This works");
    });

    done();
  },
  { prefix: "/activity" }
);

To Reproduce

Your Environment

  • node version: 15.3
  • fastify version: >=3.10
  • os: Mac

Some ideas as to what may be causing this

Prior to 3.10, this line was called twice per route:

fastify.addHook('onRoute', routeOptions => {

That's why this lines makes sure to ignore one of them:

if (routeOptions.path === routeOptions.prefix) {

Now with 3.10, the onRoute is called only once, and all of the routes are effectively ignored.

originally encountered in quirrel-dev/quirrel#49

I agree with your analysis! Would you like to send a PR to fix this module?

Please check out #98, it should fix the problem.