Skip to content

Instantly share code, notes, and snippets.

@mralexgray
Forked from richardkazuomiller/proxy.js
Last active July 11, 2016 05:05
Show Gist options
  • Save mralexgray/6ec450f4bca2043f3f88d8c0385e49df to your computer and use it in GitHub Desktop.
Save mralexgray/6ec450f4bca2043f3f88d8c0385e49df to your computer and use it in GitHub Desktop.
node-http-proxy routing proxy with websockets
httpProxy = require 'http-proxy'
proxy = httpProxy.createProxy ws:true
options =
'herp.dev': 'http://0.0.0.0:9008'
'derp.dev': 'http://0.0.0.0:3000'
server = require('http').createServer (req, res) ->
proxy.web req, res, { target: options[req.headers.host] }, (e) ->
log_error e, req
log_error = (e, req) -> return if not e
console.error e.message
console.log "#{req.headers.host} --> #{options[req.headers.host]}\n-----"
server.on 'upgrade', (req, res) ->
proxy.ws req, res, { target: options[req.headers.host] }, (e) ->
log_error e, req
server.listen 80
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment