forked from rhyolight/nupic.wallboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (50 loc) · 1.56 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
52
53
54
55
56
57
58
var _ = require('underscore')
, express = require('express')
, path = require('path')
, fs = require('fs')
, CONFIG = require('config')
, PORT = process.env.PORT || CONFIG.app.port
, ajaxHandlers = require('./server/ajaxHandlers')(CONFIG)
, issueHandler = require('./server/issueHandler')
, requestProxy = require('./server/requestProxy')
;
function writeIndexHtml() {
var layout = 'default'
, html;
if (CONFIG.layout) {
layout = CONFIG.layout;
}
html = fs.readFileSync(path.join(__dirname, 'layouts', layout + '.html'));
fs.writeFileSync(path.join(__dirname, 'client', 'index.html'), html);
}
function normalizeConfig(cfg) {
if (cfg.refresh_rate) {
_.each(cfg.monitors, function(monitor) {
if (! monitor.refresh_rate) {
monitor.refresh_rate = cfg.refresh_rate;
}
});
}
}
function startServer() {
console.log('starting server');
var app = express()
.use(express.json())
.use(express.urlencoded())
.use(express.static(__dirname + '/client'))
// HTTP request proxy
.use(requestProxy());
// Adding handling for system ajax calls.
_.each(ajaxHandlers, function(handler, path) {
app.get(path, handler);
});
// Handles requests for issue reports across all repos.
app.get('/issues', issueHandler);
app.listen(PORT, function() {
console.log('nupic.wallboard server running on\n'
+ '\thttp://localhost:' + PORT);
});
}
normalizeConfig(CONFIG);
writeIndexHtml();
startServer();