Question

Socket.io on App Platform?

Hi, I cannot seem to set up a very simple socket.io/express server on App Platform. Works fine locally, but once I deploy it as a web-server on App Platform, the express server seems to run, but not the socket connection.

Here is the simple index.js file:

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require('socket.io');
const io = new Server(server);

app.get('/', (req, res) => {
  res.sendFile('index.html', { root: __dirname });
});

io.on('connection', (socket) => {
  console.log('a user connected');
});

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

server.listen(PORT, () => {
  console.log('listening on *:', PORT);
});

When I try to ping it:

curl "<the server URL>/socket.io/?EIO=4&transport=polling"

I get no response.

Any ideas?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer