-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (32 loc) · 1.51 KB
/
Copy pathapp.js
File metadata and controls
54 lines (32 loc) · 1.51 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
46
47
48
49
50
51
52
53
54
const cors = require("cors");
const express = require("express");
const app = express();
app.use(cors());
const db = require("./db/connection");
const exportedTopic = require("./app/controllers/topics.controller");
const exportedArticle = require("./app/controllers/articles.controller");
const exportedComments = require("./app/controllers/comments.controller");
const exportedUsers = require("./app/controllers/users.controller");
const getNews = exportedTopic.getNews;
const getAllTopics = exportedTopic.getAllTopics;
const getArticleById = exportedArticle.getArticleById;
const getAllArticles = exportedArticle.getAllArticles;
const getCommentsForArticle = exportedArticle.getCommentsForArticle;
const addCommentForArticle = exportedArticle.addCommentForArticle;
const updateArticleById = exportedArticle.updateArticleById;
const deleteCommentById = exportedComments.deleteCommentById;
const getAllUsers = exportedUsers.getAllUsers;
app.use(express.json());
app.get("/api", getNews);
app.get("/api/topics", getAllTopics);
app.get("/api/articles/:article_id", getArticleById);
app.get("/api/articles", getAllArticles);
app.get("/api/articles/:article_id/comments", getCommentsForArticle);
app.post("/api/articles/:article_id/comments", addCommentForArticle);
app.patch("/api/articles/:article_id", updateArticleById);
app.delete("/api/comments/:comment_id", deleteCommentById);
app.get("/api/users", getAllUsers);
app.use((req, res, next) => {
res.status(404).send({ msg: "Route not found" });
});
module.exports = app;