forked from coolaj86/goldilocks.js
		
	added way to specify proxy destination
This commit is contained in:
		
							parent
							
								
									be67f04afa
								
							
						
					
					
						commit
						21a77ad10a
					
				@ -71,7 +71,7 @@ function readConfigAndRun(args) {
 | 
			
		||||
  config = recase.camelCopy(config);
 | 
			
		||||
 | 
			
		||||
  if (!config.dns) {
 | 
			
		||||
    config.dns = { modules: { name: 'proxy', port: 3053 } };
 | 
			
		||||
    config.dns = { modules: [{ name: 'proxy', port: 3053 }] };
 | 
			
		||||
  }
 | 
			
		||||
  // Use Object.assign to add any properties needed but not defined in the mdns config.
 | 
			
		||||
  // It will first copy the defaults into an empty object, then copy any real config over that.
 | 
			
		||||
@ -82,7 +82,7 @@ function readConfigAndRun(args) {
 | 
			
		||||
    config.tcp = {};
 | 
			
		||||
  }
 | 
			
		||||
  if (!config.http) {
 | 
			
		||||
    config.http = { modules: { name: 'proxy', port: 3000 } };
 | 
			
		||||
    config.http = { modules: [{ name: 'proxy', domains: ['*'], port: 3000 }] };
 | 
			
		||||
  }
 | 
			
		||||
  if (!config.tls) {
 | 
			
		||||
    console.log("TODO: tls: { modules: { name: 'acme', email: 'foo@bar.com', domains: [ '*' ] } }");
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ http:
 | 
			
		||||
          from: /nowhere/in/particular
 | 
			
		||||
          to: /just/an/example
 | 
			
		||||
        - name: proxy
 | 
			
		||||
          address: '127.0.0.1:3001'
 | 
			
		||||
          port: 3001
 | 
			
		||||
 | 
			
		||||
  modules:
 | 
			
		||||
    - name: redirect
 | 
			
		||||
@ -47,7 +47,8 @@ http:
 | 
			
		||||
    - name: proxy
 | 
			
		||||
      domains:
 | 
			
		||||
        - localhost.daplie.me
 | 
			
		||||
      address: '127.0.0.1:4000'
 | 
			
		||||
      host: locahost
 | 
			
		||||
      port: 4000
 | 
			
		||||
    - name: static
 | 
			
		||||
      domains:
 | 
			
		||||
        - '*.localhost.daplie.me'
 | 
			
		||||
 | 
			
		||||
@ -74,22 +74,36 @@ module.exports.create = function (deps, config) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function dnsListener(msg) {
 | 
			
		||||
    var dgram = require('dgram');
 | 
			
		||||
    var socket = dgram.createSocket('udp4');
 | 
			
		||||
    socket.send(msg, config.dns.proxy.port, config.dns.proxy.address || '127.0.0.1');
 | 
			
		||||
    if (!Array.isArray(config.dns.modules)) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    var socket = require('dgram').createSocket('udp4');
 | 
			
		||||
    config.dns.modules.forEach(function (mod) {
 | 
			
		||||
      if (mod.name !== 'proxy') {
 | 
			
		||||
        console.warn('found bad DNS module', mod);
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      var dest = require('./domain-utils').separatePort(mod.address || '');
 | 
			
		||||
      dest.port = dest.port || mod.port;
 | 
			
		||||
      dest.host = dest.host || mod.host || 'localhost';
 | 
			
		||||
      socket.send(msg, dest.port, dest.host);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function createTcpForwarder(mod) {
 | 
			
		||||
    return function (conn) {
 | 
			
		||||
      var newConnOpts = require('./domain-utils').separatePort(mod.address);
 | 
			
		||||
    var dest = require('./domain-utils').separatePort(mod.address || '');
 | 
			
		||||
    dest.port = dest.port || mod.port;
 | 
			
		||||
    dest.host = dest.host || mod.host || 'localhost';
 | 
			
		||||
 | 
			
		||||
    return function (conn) {
 | 
			
		||||
      var newConnOpts = {};
 | 
			
		||||
      ['remote', 'local'].forEach(function (end) {
 | 
			
		||||
        ['Family', 'Address', 'Port'].forEach(function (name) {
 | 
			
		||||
          newConnOpts[end+name] = conn[end+name];
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      deps.proxy(conn, newConnOpts);
 | 
			
		||||
      deps.proxy(conn, Object.assign({}, dest, newConnOpts));
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -224,7 +224,9 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
 | 
			
		||||
 | 
			
		||||
    opts.firstChunk = Buffer.concat([head, body]);
 | 
			
		||||
 | 
			
		||||
    var newConnOpts = separatePort(mod.address);
 | 
			
		||||
    var newConnOpts = separatePort(mod.address || '');
 | 
			
		||||
    newConnOpts.port = newConnOpts.port || mod.port;
 | 
			
		||||
    newConnOpts.host = newConnOpts.host || mod.host || 'localhost';
 | 
			
		||||
    newConnOpts.servername = separatePort(headers.host).host;
 | 
			
		||||
    newConnOpts.data = opts.firstChunk;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -186,7 +186,9 @@ module.exports.create = function (deps, config, netHandler) {
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  function proxy(socket, opts, mod) {
 | 
			
		||||
    var newConnOpts = require('../domain-utils').separatePort(mod.address);
 | 
			
		||||
    var newConnOpts = require('../domain-utils').separatePort(mod.address || '');
 | 
			
		||||
    newConnOpts.port = newConnOpts.port || mod.port;
 | 
			
		||||
    newConnOpts.host = newConnOpts.host || mod.host || 'localhost';
 | 
			
		||||
    newConnOpts.servername = opts.servername;
 | 
			
		||||
    newConnOpts.data = opts.firstChunk;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user