masq
Version:
A simple local dns server extracted from Pow
84 lines (66 loc) • 2.5 kB
JavaScript
// Generated by CoffeeScript 2.0.0-beta2
(function() {
var Configuration, async, compilePattern, fs, getUserEnv, path, sourceScriptEnv;
fs = require("fs");
path = require("path");
async = require("async");
({sourceScriptEnv} = require("./utils"));
({getUserEnv} = require("./utils"));
module.exports = Configuration = (function() {
class Configuration {
static loadUserConfigurationEnvironment(callback) {
return getUserEnv((err, env) => {
var p;
if (err) {
return callback(err);
} else {
return fs.exists(p = this.userConfigurationPath, function(exists) {
if (exists) {
return sourceScriptEnv(p, env, callback);
} else {
return callback(null, env);
}
});
}
});
}
static getUserConfiguration(callback) {
return this.loadUserConfigurationEnvironment(function(err, env) {
if (err) {
return callback(err);
} else {
return callback(null, new Configuration(env));
}
});
}
constructor(env = process.env) {
this.initialize(env);
}
initialize(env) {
var base, ref, ref1, ref2, ref3, ref4;
this.bin = (ref = env.MASQ_BIN) != null ? ref : path.join(__dirname, "../bin/masq");
this.dnsPort = (ref1 = env.MASQ_DNS_PORT) != null ? ref1 : 20560;
this.domains = (ref2 = (ref3 = env.MASQ_DOMAINS) != null ? ref3 : env.MASQ_DOMAINS) != null ? ref2 : "dev";
this.domains = (ref4 = typeof (base = this.domains).split === "function" ? base.split(",") : void 0) != null ? ref4 : this.domains;
this.allDomains = this.domains.concat(/\d+\.\d+\.\d+\.\d+\.xip\.io$/, /[0-9a-z]{1,7}\.xip\.io$/);
return this.dnsDomainPattern = compilePattern(this.domains);
}
toJSON() {
var i, key, len, ref, result;
result = {};
ref = this.constructor.optionNames;
for (i = 0, len = ref.length; i < len; i++) {
key = ref[i];
result[key] = this[key];
}
return result;
}
};
Configuration.userConfigurationPath = path.join(process.env.HOME, ".masqconfig");
Configuration.optionNames = ["bin", "dnsPort", "domains"];
return Configuration;
})();
compilePattern = function(domains) {
return RegExp(`((^|\\.)(${domains.join("|")}))\\.?$`, "i");
};
}).call(this);