socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Subdomain client

Open mamdi52 opened this issue 8 years ago • 5 comments

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);

mamdi52 avatar Dec 07 '17 13:12 mamdi52

Are you using NGINX or Apache?

yordadev avatar Dec 13 '17 05:12 yordadev

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

MikeDabrowski avatar Aug 04 '18 18:08 MikeDabrowski

Closed due to inactivity, please reopen if needed.

darrachequesne avatar Jan 28 '21 13:01 darrachequesne

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 avatar Aug 04 '23 20:08 hammadalimughal

@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

darrachequesne avatar Aug 07 '23 05:08 darrachequesne