34 lines
		
	
	
	
		
			665 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			665 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env node
 | 
						|
 | 
						|
var http = require('http'),
 | 
						|
    httpProxy = require('http-proxy');
 | 
						|
 | 
						|
//
 | 
						|
// Create a proxy server with custom application logic
 | 
						|
//
 | 
						|
var proxy = new httpProxy.createProxyServer({});
 | 
						|
 | 
						|
var proxyServer = http.createServer(function (req, res) {
 | 
						|
  proxy.web(req, res, {
 | 
						|
    target: {
 | 
						|
      host: 'localhost',
 | 
						|
      port: 4001
 | 
						|
    }
 | 
						|
  });
 | 
						|
});
 | 
						|
 | 
						|
//
 | 
						|
// Listen to the `upgrade` event and proxy the
 | 
						|
// WebSocket requests as well.
 | 
						|
//
 | 
						|
proxyServer.on('upgrade', function (req, socket, head) {
 | 
						|
  proxy.ws(req, socket, head, {
 | 
						|
    target: {
 | 
						|
      host: 'localhost',
 | 
						|
      port: 4001
 | 
						|
    }
 | 
						|
  });
 | 
						|
});
 | 
						|
 | 
						|
console.log("listening on port 4000")
 | 
						|
proxyServer.listen(4000);
 |