forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (30 loc) · 847 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
33
34
35
36
37
import express from 'express';
import cors from 'cors';
import './config/passport.config.js';
import usersRouter from './routes/users.routes.js';
import contactsRouter from './routes/contacts.routes.js';
import { AVATARS_DIR } from './helpers/globalVariables.js';
const app = express();
app.use(express.json());
app.use(cors());
app.use('/api/users', usersRouter);
app.use('/api/contacts', contactsRouter);
app.use('/api/avatars', express.static(AVATARS_DIR));
app.use((_, res, __) => {
res.status(404).json({
status: 'error',
code: 404,
message: `The given endpoint does not exist`,
data: 'Not found',
});
});
app.use((err, _, res, __) => {
console.log(err.stack);
res.status(500).json({
status: 'fail',
code: 500,
message: err.message,
data: 'Internal Server Error',
});
});
export default app;