-
Notifications
You must be signed in to change notification settings - Fork 2
/
router.js
61 lines (50 loc) · 1.32 KB
/
router.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
59
60
61
'use strict';
var requestHandlers = require('./requestHandlers');
var routes = function (app) {
var s3Base = 'http://data.sciencerely.org/mongolia';
////
//// Version 1
////
app.get('/', function (req, res) {
res.redirect(301, s3Base);
});
app.get('/api', function (req, res) {
res.redirect(301, s3Base + '/api.html');
});
app.get('/charts', function (req, res) {
res.redirect(301, s3Base + '/charts.html');
});
////
// Version 1
////
app.get('/1/mostRecentMeasurements', function (req, res) {
requestHandlers.getMostRecentMeasurements(function (err, data) {
if (err) {
res.end(undefined);
return;
}
res.end(JSON.stringify(data));
});
});
app.get('/1/dailyMeasurements', function (req, res) {
requestHandlers.getDailyMeasurements(function (err, data) {
if (err) {
res.end(undefined);
return;
}
res.end(JSON.stringify(data));
});
});
app.get('/1/mostRecent', function (req, res) {
requestHandlers.getMostRecent(req, res);
});
app.get('/1/sendTweet', function (req, res) {
var key = req.param('key');
if (key && key == process.env.SERVER_KEY) {
requestHandlers.sendTweet(req, res);
} else {
res.end('{"results": {"error": "incorrect key"}}');
}
});
};
module.exports = routes;