I cannot connect to my Node.js WebSocket Server

don 0 Reputation points
2023-08-05T13:36:09.73+00:00

Hi,

Newbie in Azure here and I am just trying out how to deploy Node.js application in Azure App Services

I am following this link when I am trying to deploy my Node.js WebSocket server in Azure App services.

https://github.com/Azure/app-service-linux-docs/blob/master/HowTo/WebSockets/use_websockets_with_nodejs.md

When I try to run my Node.js with WebSocket server locally then it works with no issues.

But when I try to deploy it in Azure App services then I cannot connect to this

wss://<name>-webapp.azurewebsites.net

The basic quickstart website is available though

I have tried the following already based on what I have been reading on the internet

  • Deployed it in B1 or B2 and not on F1 free. I tried the premium as well
  • Use Windows instead of Linux during deployment and turn on WebSocket on the configuration option.

I have read somewhere that WebSocket is available even in F1 free services but I am not able to make it work.

Any hints, please?

My app.js taken from the quickstart guide for Node.js https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-vscode

var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
const WebSocket = require("ws");

var indexRouter = require("./routes/index");
var usersRouter = require("./routes/users");

var app = express();

// const port = process.env.PORT || 3000;
const wss = new WebSocket.Server({ server: app });
wss.on("connection", function connection(ws) {
  ws.on("message", function incoming(message) {
    console.log("received: %s", message);
  });

  ws.send("something from server");
});

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

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.