forked from coolaj86/goldilocks.js
		
	can haz wss
This commit is contained in:
		
							parent
							
								
									47d72365cc
								
							
						
					
					
						commit
						3aa1085008
					
				@ -5,6 +5,7 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
 | 
			
		||||
  var app = express();
 | 
			
		||||
  var adminApp = require('./admin').create(deps, conf);
 | 
			
		||||
  var domainMatches = require('../match-domain').match;
 | 
			
		||||
  var proxyRoutes = [];
 | 
			
		||||
 | 
			
		||||
  var adminDomains = [
 | 
			
		||||
    /\blocalhost\.admin\./
 | 
			
		||||
@ -112,16 +113,30 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
 | 
			
		||||
      res.end(require('../proxy-err-resp').getRespBody(err, conf.debug));
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return function (req, res, next) {
 | 
			
		||||
      var hostname = req.headers.host.split(':')[0];
 | 
			
		||||
      var relevant = mod.domains.some(function (pattern) {
 | 
			
		||||
        return domainMatches(pattern, hostname);
 | 
			
		||||
      });
 | 
			
		||||
    return {
 | 
			
		||||
      web: function (req, res, next) {
 | 
			
		||||
        var hostname = req.headers.host.split(':')[0];
 | 
			
		||||
        var relevant = mod.domains.some(function (pattern) {
 | 
			
		||||
          return domainMatches(pattern, hostname);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
      if (relevant) {
 | 
			
		||||
        proxy.web(req, res);
 | 
			
		||||
      } else {
 | 
			
		||||
        next();
 | 
			
		||||
        if (relevant) {
 | 
			
		||||
          proxy.web(req, res);
 | 
			
		||||
        } else {
 | 
			
		||||
          next();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    , ws: function (req, socket, head, next) {
 | 
			
		||||
        var hostname = req.headers.host.split(':')[0];
 | 
			
		||||
        var relevant = mod.domains.some(function (pattern) {
 | 
			
		||||
          return domainMatches(pattern, hostname);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        if (relevant) {
 | 
			
		||||
          proxy.ws(req, socket, head);
 | 
			
		||||
        } else {
 | 
			
		||||
          next();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
@ -164,7 +179,9 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
 | 
			
		||||
 | 
			
		||||
  (conf.http.modules || []).forEach(function (mod) {
 | 
			
		||||
    if (mod.name === 'proxy') {
 | 
			
		||||
      app.use(createProxyRoute(mod));
 | 
			
		||||
      var proxyRoute = createProxyRoute(mod);
 | 
			
		||||
      proxyRoutes.push(proxyRoute);
 | 
			
		||||
      app.use(proxyRoute.web);
 | 
			
		||||
    }
 | 
			
		||||
    else if (mod.name === 'static') {
 | 
			
		||||
      app.use(createStaticRoute(mod));
 | 
			
		||||
@ -175,5 +192,26 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  app.use(respond404);
 | 
			
		||||
  return require('http').createServer(app);
 | 
			
		||||
 | 
			
		||||
  var server = require('http').createServer(function (req, res) {
 | 
			
		||||
    app(req, res)
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  server.on('upgrade', function (req, socket, head) {
 | 
			
		||||
    if (!proxyRoutes.length) {
 | 
			
		||||
      socket.end();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function proxyWs() {
 | 
			
		||||
      var proxyRoute = proxyRoutes.shift();
 | 
			
		||||
      if (!proxyRoute) {
 | 
			
		||||
        socket.end();
 | 
			
		||||
      }
 | 
			
		||||
      proxyRoute.ws(req, socket, head, proxyWs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    proxyWs();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return server;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user