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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/**
* Server side code using the express framework running on a Node.js server.
*
* Load the express framework and create an app.
*/
const express = require('express');
const app = express();
/**
* Host all files in the client folder as static resources.
* That means: localhost:8080/someFileName.js corresponds to client/someFileName.js.
*/
app.use(express.static('client'));
/**
* Allow express to understand json serialization.
*/
app.use(express.json());
/**
* Our code starts here.
*/
const attractions = [
{
name: "De Efteling",
description: "The Dutch fairy tale themed park. In high demand!",
adultPrice: 32,
kidsPrice: 32,
minimumNumberOfAdults: 2,
minimumNumberOfKids: 1,
discount: 15,
available: 1,
location: { lat: 51.649718, lon: 5.043689 },
},
{
name: "Madurodam",
description: "The Netherlands smallest theme park.",
adultPrice: 25,
kidsPrice: 20,
minimumNumberOfAdults: 1,
minimumNumberOfKids: 2,
discount: 25,
available: 5,
location: { lat: 52.0994779, lon: 4.299619900000039 },
},
{
name: "Toverland",
description: "Experience magic and wonder.",
adultPrice: 30,
kidsPrice: 30,
minimumNumberOfAdults: 2,
minimumNumberOfKids: 2,
discount: 33,
available: 3,
location: { lat: 51.3968994, lon: 5.9825161 },
},
{
name: "Walibi Holland",
description: "Need an Adrenaline Rush?",
adultPrice: 37,
kidsPrice: 37,
minimumNumberOfAdults: 4,
minimumNumberOfKids: 0,
discount: 10,
available: 20,
location: { lat: 52.438554, lon: 5.766986 },
},
{
name: "Duinrell",
description: "From the Kikkerbaan to the Tikibad.",
adultPrice: 22,
kidsPrice: 19,
minimumNumberOfAdults: 1,
minimumNumberOfKids: 3,
discount: 7,
available: 20,
location: { lat: 52.147433, lon: 4.383922 },
},
{
name: "Slagharen",
description: "Fun for the whole family in a true western style.",
adultPrice: 28,
kidsPrice: 20,
minimumNumberOfAdults: 2,
minimumNumberOfKids: 2,
discount: 50,
available: 2,
location: { lat: 52.6249522, lon: 6.563149500000009 },
},
{
name: "Drievliet",
description: "Come and experience our wonderful attractions.",
adultPrice: 26,
kidsPrice: 24,
minimumNumberOfAdults: 1,
minimumNumberOfKids: 2,
discount: 25,
available: 0,
location: { lat: 52.052608, lon: 4.352633 },
},
]
/**
* A route is like a method call. It has a name, some parameters and some return value.
*
* Name: /api/attractions
* Parameters: the request as made by the browser
* Return value: the list of attractions defined above as JSON
*
* In addition to this, it has a HTTP method: GET, POST, PUT, DELETE
*
* Whenever we make a request to our server,
* the Express framework will call one of the methods defined here.
* These are just regular functions. You can edit, expand or rewrite the code here as needed.
*/
app.get("/api/attractions", function (request, response) {
console.log("Api call received for /attractions");
response.json(attractions)
});
app.post("/api/placeorder", function (request, response) {
console.log("Api call received for /placeorder");
/**
* Send the status code 200 back to the clients browser.
* This means OK.
*/
response.sendStatus(200);
});
app.get("/api/myorders", function (request, response) {
console.log("Api call received for /myorders");
response.sendStatus(200);
});
app.get("/api/admin/edit", function (request, response) {
console.log("Api call received for /admin/edit");
response.sendStatus(200);
});
/**
* Make our webserver available on port 8000.
* Visit localhost:8000 in any browser to see your site!
*/
app.listen(8000, () => console.log('Example app listening on port 8000!'));
|