-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
56 lines (47 loc) · 1.68 KB
/
api.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
var express = require('express');
var http = require('http');
var moment = require('moment');
var app = express();
var runsBehindProxy = false;
function getRequestOptionsForPath(path) {
var eventHost = 'event.polarismedia.no';
var proxyHost = "www-proxy.statoil.no";
return {
host: runsBehindProxy ? proxyHost : eventHost,
port: 80,
path: path,
headers: runsBehindProxy ? {Host: eventHost} : {}
};
}
function getListEventsPath() {
// http://event.polarismedia.no/adressa/search/?dateFrom=2016-02-20&dateTo=2016-03-05&categories=8&page=1
//var eventPath = '/adressa/events/11948';
var dateFormat = 'YYYY-MM-DD';
var today = new Date();
var fiveDaysAhead = new Date(today);
fiveDaysAhead.setDate(fiveDaysAhead.getDate() + 5);
var path = '/adressa/search/?dateFrom=' + moment(today).format(dateFormat) +
'&dateTo=' + moment(fiveDaysAhead).format(dateFormat) + '&categories=8&page=1';
console.log(path);
return getRequestOptionsForPath(path);
}
app.use(express.static('client'));
app.get('/api/events', function (requestFromClient, responseToClient) {
requestFromClient = http.request(getListEventsPath(), function (responseFromEventServer) {
// Continuously update stream with data
var body = '';
responseFromEventServer.on('data', function (data) {
body += data;
});
responseFromEventServer.on('end', function () {
responseToClient.send(JSON.parse(body));
});
});
requestFromClient.end();
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
// Sample modification
// Another one
// Third one