Can't connect client to glitch server

Hi, I’m working on a small Glitch project to develop a simple chat system. I’m using and some other modules. My problem is that i can’t manage to connect sockets to the glitch host of my project. I recreated the project on my pc and everything works fine, which leads me to think that the problem is that i’m trying the wrong host name…

After setting my server i’m trying something like:

const socket = io.connect();

So the question is: which host should i put there? I tried with both my project url and project url/chat (which is the route serving the html page which loads the socket).

So here’s my issue in detail (with source code too):

Thanks a lot! :slight_smile:

Hi @Farlokko, welcome to the Glitch Forums!

I’ve not used myself, but a trivial test of the docs looks like things work more or less as expected; you can see my example at; I’m using the bare hostname for the project as the connection string.

As I would expect from that configuration, when I load the homepage it connects to running in my Glitch project. Glitch logs { my: 'data' } as expected from!/simple-socket-io-test?path=public/client.js:7:0, and my browser logs {hello: "world"} as expected from!/simple-socket-io-test?path=server.js:27:0.

My simplified remix of your project works similarly when I remove the passport.socketio dependency, which makes me wonder if there’s something amiss with that configuration that means that isn’t properly opening the connection on the server. That may be a red herring, since I’m not 100% sure I have that configured properly in my remix.

Thanks for your kind and detailed reply @cori . I partially solved the problem thanks to you.

As you stated there was an error in passport.socketio; i changed the store to the mongostore and everything works. However there is a line which i had to delete to make it work inside the io.use(passportSocketIo.authorize middleware, which is:

key: ‘express.sid’

The documentation says that i should put “the name of the cookie where express/connect stores its session_id”. How can i find it? I just found ‘express.sid’ but i can’t understand if that’s a placeholder and how to get the real cookie’s name.

Anyway this has nothing to do with glitch of course.

Thanks a lot :smiley:

Hey @Farlokko I haven’t tested this, but the express-session docs indicate that the default cookie name is ‘connect.sid’ and it appears you could set it in the app.use block here.

I changed express.sid to connect.sid in my “io.use(passportSocketIo.authorize)” as stated in passport.socketio docs and it worked!

I can’t thank you enough, really! <3

Have a good day, thanks again!

1 Like