I have an app of NextJS
frontend server and a backend server(irrelevant in this question), each defined and deployed as docker-compose
service.
Since the hostname of the backend server is dynamic by docker DNS, I would have to refer to it by its service name on NextJS server, which resolves it on runtime. I use NextJS's _middleware.ts
, which is essentially a convenient way to define a generic API Route
as far as I can tell.
This works well for HTTP requests, but for the WebSocket request that initiates the handshake, the WebSocket
class expects ws://***
format for the URL argument, which does not go through the NextJS's API Route obviously since it doesn't start with /api
.
So it's looking like I:
ws://
format, and it seems these can't be achieved at the same time for NextJS. Am I missing something?