forked from espiers13/hidden-gems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (46 loc) · 1.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require("express");
const cors = require("cors");
const app = express();
const {
getAllComments,
getGemComments,
postComment,
deleteComment,
getAllUsers,
getUserById,
postUser,
patchUser,
getEndpoints,
getGems,
getGemByID,
postGem,
patchGem
} = require("./controllers/index.controllers");
const {
handlePSQLErrors,
handleCustomErrors,
handleServerErrors,
} = require("./errors/errors");
app.use(express.json());
app.use(cors());
app.get("/api", getEndpoints);
app.get("/api/users", getAllUsers);
app.get("/api/users/:user_id", getUserById);
app.post("/api/users", postUser);
app.patch("/api/users/:user_id", patchUser);
app.get("/api/gems", getGems);
app.get("/api/gems/:gem_id", getGemByID);
app.post("/api/gems", postGem);
app.patch("/api/gems/:gem_id", patchGem);
app.get("/api/comments", getAllComments);
app.get("/api/comments/:gem_id", getGemComments);
app.post("/api/comments", postComment);
app.delete("/api/comments/:comment_id", deleteComment);
//Error Handling
app.use(handlePSQLErrors);
app.use(handleCustomErrors);
app.use(handleServerErrors);
app.all("/*", (req, res) => {
res.status(404).send({ msg: "Page not found!" });
});
module.exports = app;