-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
85 lines (74 loc) · 2.08 KB
/
server.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var http = require('http');
var path = require('path');
var express = require('express');
var router = express();
var server = http.createServer(router);
var airports = require("./airports.json");
router.use(express.static(path.resolve(__dirname, 'client')));
Date.prototype.addHours= function(h){
this.setHours(this.getHours()+h);
return this;
}
router.post('/test2', function(req, res){
var x = [ 1, 2, 3]
res.json(x);
});
router.get('/calculateSchedule', function(req, res) {
var events = [
{
timeStart: new Date(),
timeEnd: new Date().addHours(5),
type: "sleep",
text: "",
textStart: "Ideal bed time",
textEnd: "Ideal bed time"
},
{
timeStart: new Date().addHours(5),
timeEnd: new Date().addHours(7),
type: "travel",
text: "",
textStart: "Board flight",
textEnd: "Exit"
},
{
timeStart: new Date().addHours(10),
timeEnd: new Date().addHours(12),
type: "meeting",
text: "Description",
textStart: "",
textEnd: ""
},
{
timeStart: new Date().addHours(4),
timeEnd: new Date().addHours(11),
type: "night",
text: "Night at destination",
textStart: "",
textEnd: ""
}
];
res.json(events);
});
router.post('/test', function(req, res){
var email = req.param('email', null); // second parameter is default
res.send("ahoj");
});
// supports IATA codes
router.get('/airportSearch', function(req, res){
if(req.query.search != null)
{
var ucQuery = req.query.search.toUpperCase();
var airport = airports[ucQuery]; //IATA case
if(airport != null){
var airportDetails = {
IATA : req.query.search.toUpperCase(),
TimeZone : airport[2],
Name : airport[0],
City : airport[1]
};
res.json(airportDetails);
}
}
});
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0");