-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (32 loc) · 986 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
38
39
40
const express = require('express');
const mongoose = require('mongoose');
const helmet = require('helmet');
const users = require('./routes/users');
const cards = require('./routes/cards');
const { PORT = 3000 } = process.env;
const app = express();
mongoose.connect('mongodb://localhost:27017/aroundb');
app.listen(PORT, (err, res) => {
if (err) {
res.status(500).send({ message: 'An error has occurred on the server' });
}
// eslint-disable-next-line no-console
console.log(`App listening on port ${PORT}`);
});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(helmet());
app.use((req, res, next) => {
req.user = {
_id: '61d497d3012853c437420687',
};
next();
});
app.use('/users', users);
app.use('/cards', cards);
app.use((req, res) => {
res.status(404).send({ message: 'Requested resource not found' });
});
app.use((err, req, res) => {
res.status(500).send({ message: 'An error has occurred on the server' });
});