Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - Good WebServer with WebSocket-proxying & SSL support?

I really love node.js but it´s really complicating when you want to run multiple websocket servers and make them all accessible over port 80.

I'm currently running nginx, but proxying incoming websocket connections to the different websocket servers depending on the url is not possible because nginx does not support http 1.1.

I´ve tried to implement a webserver that has the functionality on my own, but it is really complicated when it comes to header passing etc. Another thing is SSL support. It´s not easy to support it.

So, does anyone know a good solution to do the things i mentioned?

Thanks for any help!

like image 548
Van Coding Avatar asked Dec 27 '22 22:12

Van Coding


1 Answers

I had good results using node-http-proxy by nodejitsu. As stated in their readme, they seem to support WebSockets.

Example for WebSockets (taken from their GitHub readme):

var http = require('http'),
    httpProxy = require('http-proxy');

//
// Create an instance of node-http-proxy
//
var proxy = new httpProxy.HttpProxy();

var server = http.createServer(function (req, res) {
  //
  // Proxy normal HTTP requests
  //
  proxy.proxyRequest(req, res, {
    host: 'localhost',
    port: 8000
  })
});

server.on('upgrade', function(req, socket, head) {
  //
  // Proxy websocket requests too
  //
  proxy.proxyWebSocketRequest(req, socket, head, {
    host: 'localhost',
    port: 8000
  });
});

It's production usage should be no problem since it is used for nodejitsu.com. To run the proxy app as a daemon, consider using forever.

like image 150
schaermu Avatar answered Jan 06 '23 03:01

schaermu