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

Seth Riedel 0 Reputation points
2024-08-17T22:35:46.3966667+00:00

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

  • Frontend in React, hosted in an Azure Static Web App
  • Backend in Node.js (v20 LTS) running in a linux Azure App Service
  • The API requests go to the frontend URL under /api, which is automatically proxied to the backend app service (this is all handled through the static web app configuration)

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.

I am using socket.io version 4.7.5 on both the frontend and the backend.

Any help is greatly appreciated. Thank you!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,676 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
904 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Seth Riedel 0 Reputation points
    2024-08-18T00:21:41.7866667+00:00

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

    0 comments No comments

  2. SnehaAgrawal-MSFT 21,346 Reputation points
    2024-08-20T16:01:16.25+00:00

    @Seth Riedel Glad that you were able to resolve your issue and I appreciate your effort in sharing the solution. Your contribution will undoubtedly assist others facing similar challenges.

    As the Microsoft Q&A community follows a policy where the question author cannot accept their own answer- https://video2.skills-academy.com/en-us/answers/support/accept-answer

    I've reposted your solution.  Feel free to consider "Accepting" the answer if you find it suitable.

    Update- Issue resolved-

    As Per the official docs: Only HTTP requests are supported for APIs. WebSocket, for example, is not supported

    Check- https://video2.skills-academy.com/en-us/azure/static-web-apps/apis-overview#constraints

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.