Unexpected server response: 502

Hello i’m trying to connect a project with a anthor project by websocket but i get
Unexpected server response: 502

This is my code

const wss = new ws(config.wsURI);

wss.on(‘open’, async () => {
ws.send(‘something’)
});
wss.on(‘close’, async() => {
console.log(‘disconnected’);
});

wss.on(‘message’, async (data) => {
console.log(data)
});

wss.on(‘error’, (err) => {
console.log(err.message);
});

This post was flagged by the community and is temporarily hidden.

Anything else in the logs?

You gotta have it send a User-Agent header. If you don’t send that, Glitch will reject the request before it even gets to your app, long before your app can perform the upgrade to websocket. Coincidentally, if a request to upgrade to websocket is not successfully upgraded, another part of Glitch or AWS or something breaks and you get a 502 back, which annoyingly swallows any other error information.

2 Likes

thank you very much for your help