By waverunner
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.