goldilocks.js/lib/worker.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
var config;
// Everything that uses the config should be reading it when relevant rather than
// just at the beginning, so we keep the reference for the main object and just
// change all of its properties to match the new config.
function update(conf) {
var newKeys = Object.keys(conf);
Object.keys(config).forEach(function (key) {
if (newKeys.indexOf(key) < 0) {
delete config[key];
} else {
config[key] = conf[key];
}
});
console.log('config', JSON.stringify(config));
}
function create(conf) {
var PromiseA = require('bluebird');
var OAUTH3 = require('../packages/assets/org.oauth3');
require('../packages/assets/org.oauth3/oauth3.domains.js');
require('../packages/assets/org.oauth3/oauth3.dns.js');
require('../packages/assets/org.oauth3/oauth3.tunnel.js');
OAUTH3._hooks = require('../packages/assets/org.oauth3/oauth3.node.storage.js');
config = conf;
var deps = {
messenger: process
, PromiseA: PromiseA
, OAUTH3: OAUTH3
, request: PromiseA.promisify(require('request'))
, recase: require('recase').create({})
2017-05-10 22:05:54 +00:00
// Note that if a custom createConnections is used it will be called with different
// sets of custom options based on what is actually being proxied. Most notably the
// HTTP proxying connection creation is not something we currently control.
2017-04-27 22:05:34 +00:00
, net: require('net')
};
2017-07-06 17:01:29 +00:00
deps.storage = require('./storage').create(deps, conf);
2017-05-17 20:06:24 +00:00
deps.proxy = require('./proxy-conn').create(deps, conf);
deps.socks5 = require('./socks5-server').create(deps, conf);
deps.loopback = require('./loopback').create(deps, conf);
2017-09-14 21:26:19 +00:00
deps.ddns = require('./ddns').create(deps, conf);
2017-05-17 20:06:24 +00:00
require('./goldilocks.js').create(deps, conf);
process.removeListener('message', create);
process.on('message', update);
}
process.on('message', create);