35 lines
		
	
	
	
		
			665 B
		
	
	
	
		
			Text
		
	
	
	
	
	
		
		
			
		
	
	
			35 lines
		
	
	
	
		
			665 B
		
	
	
	
		
			Text
		
	
	
	
	
	
| 
								 | 
							
								#!/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);
							 |