{"action":"opened","issue":{"url":"https://api.github.com/repos/nodejitsu/node-http-proxy/issues/891","labels_url":"https://api.github.com/repos/nodejitsu/node-http-proxy/issues/891/labels{/name}","comments_url":"https://api.github.com/repos/nodejitsu/node-http-proxy/issues/891/comments","events_url":"https://api.github.com/repos/nodejitsu/node-http-proxy/issues/891/events","html_url":"https://github.com/nodejitsu/node-http-proxy/issues/891","id":111919244,"number":891,"title":"Express + http-proxy + websockets","user":{"login":"that1guy","id":1218940,"avatar_url":"https://avatars.githubusercontent.com/u/1218940?v=3","gravatar_id":"","url":"https://api.github.com/users/that1guy","html_url":"https://github.com/that1guy","followers_url":"https://api.github.com/users/that1guy/followers","following_url":"https://api.github.com/users/that1guy/following{/other_user}","gists_url":"https://api.github.com/users/that1guy/gists{/gist_id}","starred_url":"https://api.github.com/users/that1guy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/that1guy/subscriptions","organizations_url":"https://api.github.com/users/that1guy/orgs","repos_url":"https://api.github.com/users/that1guy/repos","events_url":"https://api.github.com/users/that1guy/events{/privacy}","received_events_url":"https://api.github.com/users/that1guy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-16T22:04:48Z","updated_at":"2015-10-16T22:04:48Z","closed_at":null,"body":"I'm trying to run a proxy server on port 8081 that can re-route http traffic and socket.io traffic.  I'm using express server because I use passport for authentication.\r\n\r\nI can get http-proxy to route all http traffic on 8081 and all websocket traffic directed to 8082, but I cant figure out how to handle both protocols on one port.  Ideas?\r\n\r\nThis first technique just causes all client side websocket requests to hit the server at a rate of about 3 requests per second.  No good.\r\n````\r\nvar express  = require('express');\r\nvar app      = express();\r\n\r\nvar httpProxy = require('http-proxy');\r\nvar apiProxy = httpProxy.createProxyServer();\r\nvar bodyParser   = require('body-parser');\r\n\r\n//Enable Gzip\r\napp.use(compress());\r\n\r\n\r\n    var postingAPI = 'http://localhost:4043',\r\n        realtimeAPI = 'ws://localhost:4044',\r\n        notificationAPI = 'http://localhost:4444';\r\n\r\n    app.all(\"/v1/postings/*\", function(req, res) {\r\n        console.log('redirecting to posting api');\r\n        apiProxy.web(req, res, {target: postingAPI});\r\n    });\r\n\r\n    app.all(\"/v1/queues/*\", function(req, res) {\r\n        console.log('redirecting to notification api');\r\n        apiProxy.web(req, res, {target: notificationAPI});\r\n    });\r\n\r\n\r\n    app.on('connection', function (req, socket, head) {\r\n        apiProxy.ws(req, socket, head, {\r\n            target: realtimeAPI\r\n        });\r\n    });\r\n\r\n    app.on('join-room', function (req, socket, head) {\r\n        apiProxy.ws(req, socket, head, {\r\n            target: realtimeAPI\r\n        });\r\n    });\r\n\r\napp.use(bodyParser.json()); // get information from html forms\r\napp.use(bodyParser.urlencoded({\r\n    extended: true\r\n}));\r\n\r\n\r\n// start Node server ===========================================================\r\napp.listen(8081);\r\n````\r\n\r\nThis second method catches the websocket request, but obviously doesn't get upgraded.\r\n````\r\nvar express  = require('express');\r\nvar app      = express();\r\n\r\nvar httpProxy = require('http-proxy');\r\nvar apiProxy = httpProxy.createProxyServer();\r\nvar bodyParser   = require('body-parser');\r\n\r\n//Enable Gzip\r\napp.use(compress());\r\n\r\n\r\n    var postingAPI = 'http://localhost:4043',\r\n        realtimeAPI = 'ws://localhost:4044',\r\n        notificationAPI = 'http://localhost:4444';\r\n\r\n    app.all(\"/v1/postings/*\", function(req, res) {\r\n        console.log('redirecting to posting api');\r\n        apiProxy.web(req, res, {target: postingAPI});\r\n    });\r\n\r\n    app.all(\"/v1/queues/*\", function(req, res) {\r\n        console.log('redirecting to notification api');\r\n        apiProxy.web(req, res, {target: notificationAPI});\r\n    });\r\n\r\n    app.all(\"/socket.io/*\", function(req, res) {\r\n        console.log('redirecting to realtime api');\r\n        apiProxy.web(req, res, {target: realtimeAPI});\r\n    });\r\n\r\n\r\napp.use(bodyParser.json()); // get information from html forms\r\napp.use(bodyParser.urlencoded({\r\n    extended: true\r\n}));\r\n\r\n\r\n// start Node server ===========================================================\r\napp.listen(8081);\r\n````\r\n![ws](https://cloud.githubusercontent.com/assets/1218940/10554285/f355ba76-7416-11e5-8833-808c5d396f40.png)\r\n\r\n\r\nI've tried a 3rd method using .ws method but no luck there either.\r\n````\r\n    app.all(\"/socket.io/*\", function(req, socket, head) {\r\n        console.log('redirecting to realtime api');\r\n        apiProxy.ws(req, socket, head, {target: realtimeAPI});\r\n    });\r\n````\r\n\r\n"}}