-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (47 loc) · 1.32 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
const express = require("express");
const app = express();
app.use(express.json());
const cors = require("cors");
app.use(cors());
const { getTopics } = require("./controllers/topics.controllers.js");
const {
getAllArticles,
getArticleById,
getVotes,
} = require("./controllers/articles.controllers.js");
const { getUsers } = require("./controllers/users.controllers.js");
const {
getComment,
postComment,
removeComment,
} = require("./controllers/comments.controllers");
const { getEndPoints } = require("./controllers/apis");
const {
psqlErrors,
customErrors,
handle404,
handleFiveHundreds,
} = require("./errors/index.js");
// API
app.get("/api", getEndPoints);
// Topics
app.get("/api/topics", getTopics);
// Articles
app.get("/api/articles", getAllArticles);
app.get("/api/articles/:article_id", getArticleById);
app.patch("/api/articles/:article_id", getVotes);
// Users
app.get("/api/users", getUsers);
// Comments
app.get("/api/articles/:article_id/comments", getComment);
app.post("/api/articles/:article_id/comments", postComment);
app.delete("/api/comments/:comment_id", removeComment);
// Error handling
app.all("*", (req, res) => {
res.status(404).send({ msg: "Path not found" });
});
app.use(psqlErrors);
app.use(customErrors);
app.use(handle404);
app.use(handleFiveHundreds);
module.exports = app;