Express-Socket.IO App isn't working with my Azure WebApp
13:17 18 Dec 2021

For educational purposes I try to deploy an Express Server that is using Socket.IO. The Server should be able to deliver a static HTML Site that was built with React, answer with a "Hello Azure!" message whenever I make a GET Rest Call to http://localhost:4000/api/azure and whenever a new client connects to the site, all the other clients get a message announcing the new client.

const path = require('path');
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
const router = require('./api/azure');

const PORT = process.env.PORT || 4000;

io.on('connection', () => {
    console.log('A new user has connected!')
    io.emit('broadcast', 'A new user has connected');
});

app.use(express.json());

app.use('/api/azure', router);

app.use(express.static(path.join(__dirname, 'build')));
app.use(express.static('public'));
app.use('/', (_, res) => {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
});


server.listen(PORT, () => { 
    console.log(`Listening to http://localhost:${PORT}`); 
});

All this tasks are fulfilled without problems in localhost. The problem begins after this app is uploaded to one of my Azure WebApps.

Instead of delivering the message "Hello Azure!" when I call the https://mydomain.azurewebsites.net/api/azure it responses back with the HTML file.

The typical Socket.IO GET method for polling https://mydomain.azurewebsites.net/socket.io/?EIO=4&transport=polling&t=SomeString responses back with the HTML file, too.

Everything url extension that I give, gives me back the HTML file.

I barely know the basic stuff about WebApps. Maybe there is a configuration that I am forgetting? By the way I haven't done anything in the configuration except that I enabled the Websockets in the WebApp config.

This never happened before. The only difference is that right now I am using a free-tier just to test. Could it be that? If not, what am I doing wrong?

Thank you for your time!

node.js azure express