35 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| module.exports.create = function (deps, conf) {
 | |
|   // This should be able to handle things like default web path (i.e. /srv/www/hostname),
 | |
|   // no-www redirect, and transpilation of static assets (i.e. cached versions of raw html)
 | |
|   // but right now it's a very dumb proxy
 | |
| 
 | |
|   function createConnection(conn) {
 | |
|     var opts = conn.__opts;
 | |
|     var newConn = deps.net.createConnection({
 | |
|       port: conf.http.proxy.port
 | |
|     , host: '127.0.0.1'
 | |
| 
 | |
|     , servername: opts.servername
 | |
|     , data: opts.data
 | |
|     , remoteFamily: opts.family || conn.remoteFamily
 | |
|     , remoteAddress: opts.address || conn.remoteAddress
 | |
|     , remotePort: opts.port || conn.remotePort
 | |
|     }, function () {
 | |
|       //console.log("[=>] first packet from tunneler to '" + cid + "' as '" + opts.service + "'", opts.data.byteLength);
 | |
|       // this will happen before 'data' is triggered
 | |
|       //newConn.write(opts.data);
 | |
|     });
 | |
| 
 | |
|     newConn.pipe(conn);
 | |
|     conn.pipe(newConn);
 | |
|   }
 | |
| 
 | |
|   return {
 | |
|     emit: function (type, conn) {
 | |
|       createConnection(conn);
 | |
|     }
 | |
|   };
 | |
| };
 |