This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
51 lines (47 loc) · 1.65 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var path = require('path');
var oauth_reverse_proxy = require('./lib');
/**
* The config path can be provided as an environment variable. If not provided,
* we choose sane defaults for Windows and non-Windows.
*/
var config_dir = process.env.OAUTH_REVERSE_PROXY_CONFIG_DIR;
if (!config_dir) {
var os = require('os').type().toLowerCase();
if (os.indexOf('windows') !== -1 || os.indexOf('cygwin') !== -1) {
config_dir = "C:\\ProgramData\\oauth_reverse_proxy\\config.d\\";
} else {
config_dir = "/etc/oauth_reverse_proxy.d/";
}
}
config_dir = path.resolve(config_dir);
/**
* The logging directory can be provided as an environment variable. If not provided,
* we choose sane defaults for Windows and non-Windows.
*/
var log_dir = process.env.OAUTH_REVERSE_PROXY_LOG_DIR;
if (!log_dir) {
var os = require('os').type().toLowerCase();
if (os.indexOf('windows') !== -1 || os.indexOf('cygwin') !== -1) {
log_dir = "C:\\ProgramData\\oauth_reverse_proxy\\logs\\";
} else {
log_dir = "/var/log/oauth_reverse_proxy/";
}
}
log_dir = path.resolve(log_dir);
try {
var logger = require('./lib/logger.js').setLogDir(log_dir);
} catch(e) {
console.error("Failed to initialize logger pointing at %s", log_dir);
process.exit(1);
}
// Create an oauth_reverse_proxy instance at our configured root dir.
oauth_reverse_proxy.init(config_dir, function(err, proxy) {
// If we caught a fatal error creating the proxies, log it and pause briefly before
// exiting to give Bunyan a chance to flush this error message.
if (err) {
logger.fatal("Failed to create proxy:\n", err, err.stack);
setTimeout(function() {
process.exit(2);
}, 2000);
}
});