Seth
Seth

Reputation: 1373

WebSockets not working in Azure Static Web App -> Azure App Service

I am having issues getting websockets to work in Azure with the following setup:

I am using socket.io on both the frontend and backend. The websocket works when the transport is set to polling, so I am confident the URL is correct. However, when the transport is set to websocket, the frontend is unable to establish a connection. The backend has no log of the request, and the frontend shows the following in the console:

index-Y7P4MTLR.js:545 WebSocket connection to 'wss://<redacted>.com/api/socket.io/?EIO=4&transport=websocket' failed:

This is the frontend code:

  const socket = io(socketHost, {
    path: "/api/socket.io",
    withCredentials: true,
    transports: ["websocket"],
  });

The network tab shows the websocket requests with a status of Finished and no response body or any useful information. Any advice is greatly appreciated. Thank you!

Upvotes: 0

Views: 243

Answers (1)

Seth
Seth

Reputation: 1373

I ended up finding out the solution. Per the official docs: Only HTTP requests are supported for APIs. WebSocket, for example, is not supported

https://learn.microsoft.com/en-us/azure/static-web-apps/apis-overview#api-options

Upvotes: 1

Related Questions