-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (42 loc) · 1.31 KB
/
app.js
File metadata and controls
52 lines (42 loc) · 1.31 KB
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
const express = require("express");
const app = express();
const cors = require("cors");
const {
getAllRestaurants,
getRestaurantsByLocation,
getIndividualRestaurantByLocation,
} = require("./controllers/restaurantCon");
const { getAllPreferences } = require("./controllers/preferenceCon");
const {
getAllUsers,
getIndividualUserByUsername,
patchUserByUsername,
deleteUserByUsername,
postUserInfo,
} = require("./controllers/userCon");
app.use(cors());
app.use(express.json());
app.get("/api/restaurants", getAllRestaurants);
app.get("/api/users", getAllUsers);
app.get("/api/restaurants/:location", getRestaurantsByLocation);
app.get("/api/restaurants/:location/:name", getIndividualRestaurantByLocation);
app.get("/api/users/:username", getIndividualUserByUsername);
app.get("/api/preferences", getAllPreferences);
app.post("/api/users", postUserInfo);
app.patch("/api/users/:username", patchUserByUsername);
app.delete("/api/users/:username", deleteUserByUsername);
app.all("*", (req, res) => {
res.status(404).send({ msg: "Not Found" });
});
app.use((err, req, res, next) => {
if (err.status) {
res.status(err.status).send({ msg: err.msg });
} else {
next(err);
}
});
app.use((err, req, res, next) => {
console.log(err);
res.status(500).send({ msg: "Server Error" });
});
module.exports = app;