-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (44 loc) · 1.05 KB
/
app.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
const express = require("express");
const queries = require("./queries");
const bodyParser = require("body-parser");
const cors = require("cors");
const app = express();
// middleware
app.use(cors());
app.use(bodyParser.json());
// twilio ? goes here ?
// this displays both tables
app.get("/", (request, response) => {
queries
.list("games")
.then(games =>
response.json({
games: games
})
)
.catch(console.error);
});
// shows the games table
app.get("/games", (request, response) => {
queries
.list("games")
.then(capstone => {
response.json({ capstone });
})
.catch(console.error);
});
// gets the games data table by location name
app.get("/games/:location", (request, response) => {
queries
.read(request.params.location, "games")
.then(games => {
games ? response.json({ games }) : response.sendStatus(404);
})
.catch(console.error);
});
// it hit none of the paths
app.use((request, response) => {
response.sendStatus(404);
});
// export entire app
module.exports = app;