-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
63 lines (52 loc) · 1.46 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
var express = require("express");
var bodyParser = require("body-parser");
var path = require("path");
// Sets up the Express App
// =============================================================
var app = express();
var port = process.env.PORT || 3000;
// Sets up the Express app to handle data parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
var customers = [];
var waitlist = [];
app.get('/', function(req,res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/tables', function(req, res) {
res.sendFile(path.join(__dirname, 'tables.html'));
});
app.get('/reserve', function(req, res) {
res.sendFile(path.join(__dirname, 'reservation.html'))
});
app.get('/api/tables', function(req, res) {
/*for (var i = 0; i < 4; i++) {
res.json(customers[i]);
}*/
return res.json(customers);
});
app.get('/api/waitlist', function(req, res) {
/*for (var i = 5; i < customers.length; i++) {
res.json(customers[i]);
}*/
return res.json(waitlist);
});
app.post('/api/clear', function(req, res) {
customers = [];
waitlist = [];
});
app.post('/api/new', function(req, res) {
console.log('Works');
var newCustomer = req.body;
if (customers.length >= 5) {
waitlist.push(newCustomer);
} else {
customers.push(newCustomer);
}
res.json(newCustomer);
});
app.listen(port, function() {
console.log("App listening on PORT " + port);
});