-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (45 loc) · 1.71 KB
/
index.js
File metadata and controls
57 lines (45 loc) · 1.71 KB
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
52
53
54
55
56
57
#!/usr/bin/env node
/** Get environment variables */
try{
require('./env')();
}catch(err){
console.log('I recommend you try making an env file');
}
/** module dependencies */
var HttpMaster = require('http-master');
var httpmaster = new HttpMaster();
/* Get domain name and port from environment and store in express */
var DOMAIN_NAME = process.env.DOMAIN_NAME || 'localhost';
var PORT = (process.env.PROXY_PORT || 3000).toString();
/* Config for reverse proxy - some settings must be applied manually */
var config = {
"watchConfig": false, // Reload on config change - note: only works with command line
"workers": 2, // Number of workers - set higher if more requests
"ports": { // Need to set this manually
}
};
/* Create port object because keys need to be set manually */
config.ports[PORT] = {
"router": {}
};
// API port and url
config.ports[PORT].router['api.' + DOMAIN_NAME] = process.env.API_URL || 3002;
// Website port and url
config.ports[PORT].router['*?.' + DOMAIN_NAME] = process.env.WEBSITE_URL || 3001;
// Catch rest for apache
config.ports[PORT].router['*'] = 8080;
var log = function(msg) { console.log(msg); };
/* Called on server initialization */
httpmaster.on('allWorkersStarted', function() { console.log('Workers activated'); });
/* Called on server reload of config - why is it called twice? */
httpmaster.on('allWorkersReloaded', function() { console.log('Workers reloaded'); });
httpmaster.on('logNotice', log); // Main logger
httpmaster.on('logError', log); // Serverside error
httpmaster.on('error', log); // Something weird is happening
/* Initializes reverse proxy */
httpmaster.init(
config, // Configuration file. Settings explained there.
function(err) {
// Listening...
}
);