-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (45 loc) · 1.43 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
const express = require("express");
const cors = require('cors');
const {
getTopics,
getArticles,
getArticleById,
getCommentsArticle,
getUsers,
postCommentByArticleId,
patchVote,
} = require("./controllers");
const { errBadRequest, errTopics, errComments } = require("./errBBC");
const app = express();
app.use(cors());
app.use(express.json());
// ================== GET ==================
// ----- 3 ------
app.get("/api/topics", getTopics);
// ----- 4 ------
app.get("/api/articles", getArticles);
// ----- 5 & 11 ------
app.get("/api/articles/:article_id", getArticleById);
// ----- 6 ------
app.get("/api/articles/:article_id/comments", getCommentsArticle);
// ----- 9 ------
app.get("/api/users", getUsers);
// ----- 4 ------
app.get("/api/articles", getArticles);
// ================== POST ==================
// ----- 7 ------
app.post("/api/articles/:article_id/comments", postCommentByArticleId);
// ================== PATCH ==================
// ----- 8 ------
app.patch("/api/articles/:article_id", patchVote);
// ----- 10 ------
// ----- 12 ------
// HANDLING MIDLLEWARE ERRORS
// app.use((err, req, res, next) => {
// console.log("========= MY LOG ===========",err);
// res.status(500).send({ msg: "Internal Server 33333rror" });
// });
app.use(errBadRequest);
app.use(errTopics);
app.use(errComments);
module.exports = app;