Websockets show upgrade message

I recently added some websockets to my project. It worked fine for a while, but now visiting any page on the project shows “Upgrade required.” There is nothing in the logs or console. I am using the free version. Do I need to upgrade to use websockets?

Hi Kyleplo!

No, websockets should work with the free version.

What is a page that shows the “Upgrade required”?

This is what your faq looks like to me:

I temporarily commented-out the websocket code, and now it works. The upgrade required message looked like this:image

OK, I think I see your problem.

First, I would like to be clear - the “Upgrade required” message is not from Glitch, it is from websocket, referring to upgrading a http connection to a websocket connection: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism

Second, Glitch only maps incoming data from the internet to one port from your project, the first one you open if you open it on one of the common ports like 3000 or 8080. So when you opened a websocket server on port 8080, Glitch thought that that was the one you wanted all the traffic coming in from http://groupqueue.glitch.me to get mapped to.

To handle this, imitate @potch’s ~starter-ws and pass the http webserver to the websocket server:

// we need to create our own http server so express and ws can share it.
const server = http.createServer(app);
// pass the created server to ws
const wss = new ws.Server({ server });

Hope this helps,

Johnicholas

Thanks. I’ll try this tomorrow, I have to do schoolwork

i think it’s a 4000 response limit for free glitch allocated app runtimes maybe? try writing a front end for loop to your port listener and see if you get that message when you exceeed 4k