Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

2 differents handlers for ws and non-ws route #110

Open
ferllings opened this issue Apr 19, 2022 · 0 comments
Open

2 differents handlers for ws and non-ws route #110

ferllings opened this issue Apr 19, 2022 · 0 comments

Comments

@ferllings
Copy link

Hello,
What is the best way to use different handlers, for the same route, depending of ws or non-ws request.
For my project I need to use the same path for regular GET requests and WS requests.
e.g.

	app.Use("/ws", func(c *fiber.Ctx) error {
		if websocket.IsWebSocketUpgrade(c) {
			c.Locals("websocket", true)
		}
                return c.Next()
	})

	app.Get("/mypath", standardHandler)
	app.Get("/mypath", websocket.New(wsHandler))

With this code, the standardHandler is executed first.
And the only way I found is to test c.Locals("websocket") in standardHandler.
Is there a cleaner way to do it?
Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant