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.

proxyTable doesn't work for websocket connections

See original GitHub issue

While regular http connections works fine, ws connection still proxies to target options:

proxyTable: {
    'dev:2992'    : 'http://localhost:3000',
  }

version: 0.9.0

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
limpbrainscommented, Jan 22, 2016

@chimurai

  1. Here is my full devServer.js
var express = require('express');
var webpack = require('webpack');
var config = require('../webpack.config.dev');
var proxyMiddleware = require('http-proxy-middleware');

var app = express();
var compiler = webpack(config);

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  publicPath: config.output.publicPath
}));

app.use(require('webpack-hot-middleware')(compiler));

var onProxyRes = function (proxyRes, req, res) {
  // remove header from response
  delete proxyRes.headers['content-security-policy-report-only'];
  delete proxyRes.headers['content-security-policy'];
};

var proxy = proxyMiddleware('**', {
  target: 'http://localhost:3000',
  changeOrigin: true,
  ws: true,
  onProxyRes,
  proxyTable: {
    'live:2992'    : 'https://host.com',
  }
});

app.use(proxy);

app.listen(2992, '0.0.0.0', function(err) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Listening at http://localhost:2992');
});
  1. yes, it is a single page application.
var wsPrefix = (window.location.protocol === 'https:') ? 'wss://' : 'ws://';
var address = wsPrefix + window.location.host + '/ws';
var WS = new WebSocket(address);
0reactions
chimuraicommented, Jan 27, 2016

Awesome. Thanks for reporting and testing! 👍

Going publish the final version after some more testing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node http proxy with proxytable and websockets
But it doesn't seem to work. A quick check to see whether websockets work shows I get Unexpected response code: 400 from Chrome...
Read more >
Websocket connection behind HTTP proxy does not work
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0. Steps to reproduce: I'm trying to use a website that uses ...
Read more >
DevServer - webpack
This option allows specifying URL to web socket server (useful when you're proxying dev server and client script does not always know where...
Read more >
ionic/node_modules/http-proxy/CHANGELOG.md ... - GitLab
Provide a "proxyReq" event also for websocket connections. a05fc2d ... [fix] ensure path works on windows because path.join doesnt like URLs ed73f06 ...
Read more >
http-proxy - npm
is invoked on the object, this does not create a webserver. ... open : This event is emitted once the proxy websocket was...
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