forkattu lähteestä coolaj86/goldilocks.js
		
	update redirect
This commit is contained in:
		
							vanhempi
							
								
									7f2bca2fd9
								
							
						
					
					
						commit
						f69bbb3d66
					
				
							
								
								
									
										13
									
								
								serve.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								serve.js
									
									
									
									
									
								
							@ -58,6 +58,9 @@ function createServer(port, pubdir, content, opts) {
 | 
			
		||||
 | 
			
		||||
    var directive = { public: pubdir, content: content, livereload: opts.livereload
 | 
			
		||||
      , servername: opts.servername, expressApp: opts.expressApp };
 | 
			
		||||
    var redirectApp = require('redirect-https')({
 | 
			
		||||
      port: port
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    server.on('error', function (err) {
 | 
			
		||||
      if (opts.errorPort || opts.manualPort) {
 | 
			
		||||
@ -95,13 +98,7 @@ function createServer(port, pubdir, content, opts) {
 | 
			
		||||
 | 
			
		||||
    server.on('request', function (req, res) {
 | 
			
		||||
      if (!req.socket.encrypted) {
 | 
			
		||||
        res.statusCode = 301;
 | 
			
		||||
        res.setHeader(
 | 
			
		||||
          'Location'
 | 
			
		||||
        , 'https://' + (req.headers.host || 'localhost')
 | 
			
		||||
          + (httpsPort === opts.port ? '' : ':' + opts.port)
 | 
			
		||||
        );
 | 
			
		||||
        res.end();
 | 
			
		||||
        redirectApp(req, res);
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -270,7 +267,7 @@ function run() {
 | 
			
		||||
    return promise.then(function (matchingIps) {
 | 
			
		||||
      if (matchingIps) {
 | 
			
		||||
        if (!matchingIps.length) {
 | 
			
		||||
          console.log("Neither the attached nor external interfaces match '" + argv.servername + "'");
 | 
			
		||||
          console.info("Neither the attached nor external interfaces match '" + argv.servername + "'");
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      opts.matchingIps = matchingIps || [];
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								stages/01-serve.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								stages/01-serve.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
var https = require('httpolyglot');
 | 
			
		||||
var httpsOptions = require('localhost.daplie.com-certificates').merge({});
 | 
			
		||||
var httpsPort = 8443;
 | 
			
		||||
var redirectApp = require('redirect-https')({
 | 
			
		||||
  port: httpsPort
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var server = https.createServer(httpsOptions);
 | 
			
		||||
 | 
			
		||||
server.on('request', function (req, res) {
 | 
			
		||||
  if (!req.socket.encrypted) {
 | 
			
		||||
    redirectApp(req, res);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  res.end("Hello, Encrypted World!");
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
server.listen(httpsPort, function () {
 | 
			
		||||
  console.log('https://' + 'localhost.daplie.com' + (443 === httpsPort ? ':' : ':' + httpsPort));
 | 
			
		||||
});
 | 
			
		||||
		Ladataan…
	
	
			
			x
			
			
		
	
		Viittaa uudesa ongelmassa
	
	Block a user