Serving Websockets and HTTP from the same path in Phoenix

Is there any way to serve HTTP requests and websockets from the same path in Phoenix? I need to provide both JSON HTTP responses and handle websocket connections at the root path of an app.

I have tried using both the socket() construct and creating a custom handler, specified here. Neither work as there seems to be no way to intercept a request before it’s sent to an HTTP or websocket handler. Any ideas?

I am building a Nostr relay, which requires this functionality.

With recent changes in phoenix 1.7 this might become possible, but afaik still isn‘t at this point in time.

1 Like

I figured out how to do it. It requires Phoenix 1.7 and writing a custom handler to intercept a request before it gets to the app Endpoint. Repo here: GitHub - RiverFinancial/nostrex: Nostr relay written in Elixir