-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (27 loc) · 1.29 KB
/
Copy pathapp.js
File metadata and controls
45 lines (27 loc) · 1.29 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
const express = require("express");
const { getAllTopics } = require("./controllers/topics.controllers");
const { handlePsqlErrors, handleCustomErrors, handleServerErrors } = require("./errors/errors");
const { getEndpoints } = require("./controllers/endpoints.controllers");
const { getArticleById, getAllArticles, patchArticle } = require("./controllers/articles.controllers");
const { getAllCommentsForArticle, postNewComment, deleteComment } = require("./controllers/comments.controllers");
const { getAllUsers } = require("./controllers/users.controllers");
const cors = require("cors");
const app = express();
app.use(cors());
app.use(express.json());
app.get("/api/topics", getAllTopics);
app.get("/api", getEndpoints);
app.get("/api/articles/:article_id", getArticleById);
app.get("/api/articles", getAllArticles);
app.get("/api/articles/:article_id/comments", getAllCommentsForArticle);
app.get("/api/users", getAllUsers);
app.post("/api/articles/:article_id/comments", postNewComment);
app.patch("/api/articles/:article_id", patchArticle);
app.delete("/api/comments/:comment_id", deleteComment);
app.all("*", (_, res) => {
res.status(404).send({ status: 404, msg: "Not found" });
});
app.use(handlePsqlErrors);
app.use(handleCustomErrors);
app.use(handleServerErrors);
module.exports = app;