Created
March 26, 2018 17:07
-
-
Save stelf/c22bfa349bc190804555e58cac58c87d to your computer and use it in GitHub Desktop.
nodejs/express http proxy mix of websocket and http splitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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