-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (25 loc) · 1.28 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
const express = require('express');
const cors = require('cors');
const {getAllUsers} = require('./Controllers/usersController');
const {getAllTopics} = require('./Controllers/topicsController');
const {getCommentsByArticleId, postComment, deleteCommentById} = require('./Controllers/commentsController');
const {getAllArticles, getArticleById, patchArticle} = require('./Controllers/articlesController');
const {handleServerErrors, handles404NotFoundErrors, handlesPSQLErrors, handlesCustomErrors} = require('./errors/errorHandling.js');
const {getEndpoints} = require("./Controllers/endpointController");
const app = express()
app.use(cors());
app.use(express.json());
app.get('/api',getEndpoints)
app.get('/api/topics', getAllTopics)
app.get('/api/articles', getAllArticles)
app.get('/api/users', getAllUsers)
app.get('/api/articles/:article_id', getArticleById)
app.get('/api/articles/:article_id/comments',getCommentsByArticleId)
app.post('/api/articles/:article_id/comments', postComment)
app.patch('/api/articles/:article_id', patchArticle)
app.delete("/api/comments/:comment_id", deleteCommentById);
app.use(handles404NotFoundErrors);
app.use(handlesPSQLErrors);
app.use(handlesCustomErrors);
app.use(handleServerErrors); // keep this at the bottom of the errors list
module.exports = app