Skip to content

Websocket & middlewares #999

Open
Open
@horvbalint

Description

@horvbalint

Describe the feature

Last week I wanted to add websocket to an existing nitro app, but ran into some unexpected behaviours. I think fixing/improving these would be beneficial for everyone.

I have two main parts of my api /public/* and /protected/*. There is a middleware registered, that is authenticating the user on every /protected/* route and also adds the user object to event.context.
My plan was simple, create a /protected/ws.ts route, that is using definedEventHandler. This way (in my plan) I wouldn't need to duplicate the authentication logic and everything should work nicely. This is sadly not the case.

  • middlewares do not run for websocket routes. I think this sohuld be treated as a bug and kinda serious imo.
  • there is no way to access the event, or event.context in defineWebsocketHandler's upgrade callback. This means that even if middlewares did run, the result could not reach the websocket handler.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions