-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (34 loc) · 1.22 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
const express = require("express");
const cors = require("cors");
const app = express();
const { getAllEndpoints } = require("./controllers/api.controller.js");
const { getTopics } = require("./controllers/topics.controllers.js");
const { getUsers } = require("./controllers/users.controllers.js");
const {
getArticlesById,
getAllArticles,
getCommentsByArticleId,
postCommentByArticleId,
patchArticleById,
deleteCommentById,
} = require("./controllers/articles.controllers");
const {
badUrlHandling,
customErrorMiddleware,
handlePsqlErrorsMiddleware,
} = require("./controllers/error.controllers.js");
app.use(express.json());
app.use(cors());
app.get("/api", getAllEndpoints);
app.get("/api/topics", getTopics);
app.get("/api/articles", getAllArticles);
app.get("/api/articles/:article_id", getArticlesById);
app.get("/api/articles/:article_id/comments", getCommentsByArticleId);
app.get("/api/users", getUsers);
app.patch("/api/articles/:article_id", patchArticleById);
app.post("/api/articles/:article_id/comments", postCommentByArticleId);
app.delete("/api/comments/:comment_id", deleteCommentById);
app.all("/*", badUrlHandling);
app.use(customErrorMiddleware);
app.use(handlePsqlErrorsMiddleware);
module.exports = app;