question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

websocket problems 502

See original GitHub issue

I’ve logged an issue here (https://github.com/chimurai/http-proxy-middleware/issues/15) where I am having a problem with browser-sync, http-proxy-middleware and websockets

In a nutshell, I have this code

var server = {
    baseDir: baseDir,
    routes: routes
  };

  var proxies = [];

  proxies.push(proxyMiddleware('/socket.io', { 
        target: 'http://localhost:5000/' , ws: true
  }));

  server.middleware = proxies;

  browserSync.instance = browserSync.init({
    startPath: '/',
    server: server,
    browser: browser
  });

but get these errors :

woot! connection
[HPM] Upgrading to WebSocket
[HPM] Client disconnected

and the client console has

WebSocket connection to 'ws://mysite.io/socket.io/?EIO=3&transport=websocket&sid=5_BeDfck0LFYcYxPAAAA' failed: Error during WebSocket handshake: Unexpected response code: 502

and obviously, I can’t get my websocket connected.

Am I missing something or is it a bug ?

thanks

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:30 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daniel-shuycommented, Dec 27, 2018

@ibc your example does not work! Notice that your example is effectively the same as the OP’s.

1reaction
bryantpcommented, Nov 21, 2016

Hi,

I am also having an issue with websockets in server mode. Here is my gulp config:

var proxyMiddleware = require('http-proxy-middleware');

module.exports = function () {
  return {
    injectChanges: true,
    port: 3002,
    server: {
      baseDir: [
        '.tmp',
        'src
      ],
      routes: {
        '/bower_components': 'bower_components'
      },
	  middleware: [
        proxyMiddleware('/api/**', {target: 'http://localhost:8081', changeOrigin: true}),
        proxyMiddleware('/ws/**', {target: 'http://localhost:8081', changeOrigin: false, ws: true, logLevel: 'debug'}),
      ]
    },
    open: false
  };
};

It usually terminates with this error:

Connection closed before receiving a handshake response

Read more comments on GitHub >

github_iconTop Results From Across the Web

websocket - How do I fix this NGINX 502 Bad Gateway error?
I was using WebSockets over SSL (so wss:// protocol) and had 502 popping up, even though the config had worked before.
Read more >
WebSocket connection handshake Error 502 #310 - GitHub
I had some problems with it (using Cloudflare for TLS). I found the following works. .env. # //deployer.domain.com so it's wss:// but uses...
Read more >
How to Solve 502 Bad Gateway Issues? - KeyCDN Support
Having issues with a 502 Bad Gateway error? This guide gives you practical tips to solve origin not reachable problems.
Read more >
Error 502 when connecting to my project's websocket
Having the same issue with websocket connection to glitch also. While in the past it worked flawlessy, now connection just fails with status ......
Read more >
502 Bad Gateway - Socket hang up | Apigee Edge
Check the Edge Microgateway logs: · Search to see if there are any 502 errors with code ECONNRESET during a specific duration (if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found