-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (47 loc) · 1.43 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
47
48
const express = require('express');
const cors = require('cors');
const endpoints = require('./endpoints.json');
const { getCategories } = require('./controllers/categories.controller');
const {
getComments,
getCommentById,
deleteComment,
getCommentsByReviewId,
postComment,
} = require('./controllers/comments.controller');
const {
getReviewByID,
getReviews,
patchReviews,
} = require('./controllers/reviews.controller');
const {
internalServer,
handle404s,
handlePsqlErrors,
handleCustomErrors,
} = require('./Error-Handling/error');
const { getApi } = require('./controllers/api.controllers');
const {
getUsers,
getUserByUsername,
} = require('./controllers/users.controllers');
const app = express();
app.use(cors());
app.use(express.json());
app.get('/api', getApi);
app.get('/api/categories', getCategories);
app.get('/api/reviews', getReviews);
app.get('/api/reviews/:review_id', getReviewByID);
app.patch('/api/reviews/:review_id', patchReviews);
app.get('/api/reviews/:review_id/comments', getCommentsByReviewId);
app.get('/api/comments', getComments);
app.get('/api/comments/:comment_id', getCommentById);
app.delete('/api/comments/:comment_id', deleteComment);
app.post('/api/reviews/:review_id/comments', postComment);
app.get('/api/users', getUsers);
app.get('/api/users/:username', getUserByUsername);
app.all('*', handle404s);
app.use(handlePsqlErrors);
app.use(handleCustomErrors);
app.use(internalServer);
module.exports = app;