forked from coolaj86/goldilocks.js
		
	add some tunnel support
This commit is contained in:
		
							parent
							
								
									fa730f04b3
								
							
						
					
					
						commit
						fa0990b02f
					
				
							
								
								
									
										30
									
								
								lib/tunnel.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								lib/tunnel.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | module.exports.create = function (opts/*, servers*/) { | ||||||
|  |   // servers = { plainserver, server }
 | ||||||
|  |   var tunnel = require('daplie-tunnel'); | ||||||
|  |   var stunnel = require('stunnel'); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   return tunnel.token({ | ||||||
|  |     refreshToken: opts.refreshToken | ||||||
|  |   , email: opts.email | ||||||
|  |   , domains: [ opts.servername ] | ||||||
|  |   }).then(function (result) { | ||||||
|  |     // { jwt, tunnelUrl }
 | ||||||
|  |     stunnel.connect({ | ||||||
|  |       token: result.jwt | ||||||
|  |     , stunneld: result.tunnelUrl | ||||||
|  |     , locals: [ | ||||||
|  |         { protocol: 'https' | ||||||
|  |         , hostname: opts.servername | ||||||
|  |         , port: opts.port | ||||||
|  |         } | ||||||
|  |       , { protocol: 'http' | ||||||
|  |         , hostname: opts.servername | ||||||
|  |         , port: opts.insecurePort || opts.port | ||||||
|  |         } | ||||||
|  |       ] | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | }; | ||||||
							
								
								
									
										5
									
								
								serve.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								serve.js
									
									
									
									
									
								
							| @ -181,7 +181,7 @@ function createServer(port, pubdir, content, opts) { | |||||||
| 
 | 
 | ||||||
|     server.on('request', function (req, res) { |     server.on('request', function (req, res) { | ||||||
|       console.log('[' + req.method + '] ' + req.url); |       console.log('[' + req.method + '] ' + req.url); | ||||||
|       if (!req.socket.encrypted) { |       if (!req.socket.encrypted && !/\/\.well-known\/acme-challenge\//.test(req.url)) { | ||||||
|         opts.redirectApp(req, res); |         opts.redirectApp(req, res); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
| @ -424,6 +424,9 @@ function run() { | |||||||
|           } |           } | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|  |       else { | ||||||
|  |         require('./lib/tunnel.js').create(opts); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|       Object.keys(opts.ifaces).forEach(function (iname) { |       Object.keys(opts.ifaces).forEach(function (iname) { | ||||||
|         var iface = opts.ifaces[iname]; |         var iface = opts.ifaces[iname]; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user