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

1 Like

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.

3 Likes

thank you very much for your help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.