-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (26 loc) · 891 Bytes
/
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
const cors = require('cors');
const express = require("express");
const apiRouter = require('./routes/api.router.js');
const topicsRouter = require('./routes/topics.router.js');
const usersRouter = require('./routes/users.router.js');
const articlesRouter = require('./routes/articles.router.js');
const commentsRouter = require('./routes/comments.router.js');
const app = express();
const {
handleEndpointError,
handleCustomErrors,
handlePsqlErrors,
handleServerErrors,
} = require('./errors.js');
app.use(cors());
app.use(express.json());
app.use('/api', apiRouter);
app.use('/api/topics', topicsRouter);
app.use('/api/users', usersRouter);
app.use('/api/articles', articlesRouter);
app.use('/api/comments', commentsRouter);
app.all('*',handleEndpointError);
app.use(handleCustomErrors);
app.use(handlePsqlErrors);
app.use(handleServerErrors);
module.exports = app