-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (35 loc) · 1.18 KB
/
main.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
'use strict'
var fs = require('fs'),
Q = require('q'),
logger = require(__dirname + '/lib/logger.js'),
data_handler = require(__dirname + '/lib/data_handler'),
express = require('express'),
bodyParser = require('body-parser');
var app = express();
app.use(express.static('static'));
app.use(bodyParser.json());
app.get('/', function(req, res) {
res.sendFile(__dirname + "/static/html/viewer.html");
});
app.get('/region/:name', function(req, res) {
let region_name = req.params.name;
data_handler.populate_region_data_json(region_name)
.then(function(info) {
logger.info({event:'region-data-sent', region_name: region_name});
res.send(info);
})
.catch(function(error) {
logger.error({event: 'fail-to-get-region-data', region_name: region_name, error: error});
res.status(400)
.json({region_name: region_name, error: 'no data'})
})
.done();
});
app.post('/api/log/action', function(req, res) {
logger.info(JSON.stringify(req.body));
res.status(200);
});
var port = process.env.PORT || 7540;
app.listen(port, function() {
logger.info('Listening on ' + port);
});