Subdomain client
Hi,
My client side is on https://subdomain.example.com and throws error on browser when connecting Socket, like
https://example.com/socket.io/?EIO=3&transport=polling&t=M0nGsGQ 404 (Not Found)
Please provide solution , I have nodejs , expressjs in server env.
Server:
const options = { key: fs.readFileSync(__dirname + '/SSL/xyz.key', 'utf8'), cert: fs.readFileSync(__dirname + '/SSL/xyz.crt', 'utf8') };
var httpsServer = https.createServer(options, app).listen(httpsPort, function () { console.log("https server started at port " + httpsPort); }); var io = require('socket.io')(httpsServer);
Are you using NGINX or Apache?
I have similar issue. My main site is using http>https redirects, and my project under site.com/projects/project is using proxy_pass http... to server on different port. When I run server and then on my local PC I run client and direct it to connect to serverIP it runs ok. But when I build my client and put it on that server I get http://localhost:9720/socket.io/?EIO=3&transport=polling&t=MK6C88A cannot GET
Closed due to inactivity, please reopen if needed.
I am also facing similar issue I've an express app on subdomain eg: www.website.com/sub-domain it shows gives error on client side. Error is: www.website.com/socket.io/socket.io.js net::ERR_ABORTED 404
@hammadalimughal I think you need to use the path option:
import { io } from "socket.io-client";
const socket = io({
path: "/sub-domain"
});
Reference: https://socket.io/docs/v4/client-options/#path