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?
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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Maybe it’s a cors restriction issue? Did you try to enable cors params?
https://socket.io/docs/v3/handling-cors/
Btw we use socket.io on the app platform. It works fine for us.
Hey did you ever figure this out? Struggling with this right now.