Skip to content

Instantly share code, notes, and snippets.

@stelf
Created March 26, 2018 17:07
Show Gist options
  • Select an option

  • Save stelf/c22bfa349bc190804555e58cac58c87d to your computer and use it in GitHub Desktop.

Select an option

Save stelf/c22bfa349bc190804555e58cac58c87d to your computer and use it in GitHub Desktop.
nodejs/express http proxy mix of websocket and http splitter
var port = 3333;
var proxy = require('http-proxy-middleware');
var express = require('express');
var app = express();
var server = require('http').Server(app);
server.listen(port, () => {
console.log('Express listening to port '+port);
});
var wsProxy = proxy('ws://localhost:8585', {changeOrigin:true});
server.on("upgrade",function(req, socket, head) {
if (!req.url.startsWith("/wsapi/")) {
wsProxy.upgrade(req,socket,head);
}
});
app.use(proxy("/forms", {
target: 'http://localhost:4300',
cookieDomainRewrite:true} ));
app.use(proxy({
target: 'http://localhost',
cookieDomainRewrite:true } ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment