| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  | '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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-06 01:08:10 -06:00
										 |  |  |   function createConnection(conn) { | 
					
						
							|  |  |  |     var opts = conn.__opts; | 
					
						
							|  |  |  |     var newConn = deps.net.createConnection({ | 
					
						
							|  |  |  |       port: conf.http.proxy.port | 
					
						
							|  |  |  |     , host: '127.0.0.1' | 
					
						
							| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-06 01:08:10 -06:00
										 |  |  |     , 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);
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     newConn.pipe(conn); | 
					
						
							|  |  |  |     conn.pipe(newConn); | 
					
						
							| 
									
										
										
										
											2017-05-06 01:08:10 -06:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-06 01:08:10 -06:00
										 |  |  |   return { | 
					
						
							|  |  |  |     emit: function (type, conn) { | 
					
						
							|  |  |  |       createConnection(conn); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  | }; |