-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (37 loc) · 1.11 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
const express = require("express");
const {
getEndpoints,
getTopics,
getArticleById,
getArticles,
getCommentsByArticleId,
postComment,
patchArticleVotes,
deleteCommentById,
getUsers,
} = require("./controllers");
const {
invalidArticleIdType,
usernameNotFound,
customErrorHandler,
} = require("./error-handlers");
const cors = require("cors");
const app = express();
app.use(cors());
app.use(express.json());
app.get("/api", getEndpoints);
app.get("/api/topics", getTopics);
app.get("/api/articles", getArticles);
app.get("/api/articles/:article_id", getArticleById);
app.get("/api/articles/:article_id/comments", getCommentsByArticleId);
app.get("/api/users", getUsers);
app.post("/api/articles/:article_id/comments", postComment);
app.patch("/api/articles/:article_id", patchArticleVotes);
app.delete("/api/comments/:comment_id", deleteCommentById);
app.use(invalidArticleIdType);
app.use(customErrorHandler);
app.use(usernameNotFound);
app.all("*", (request, response, next) => {
response.status(404).send({ msg: "path not found" });
}); // response for an invalid enpoint
module.exports = app;