-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (50 loc) · 1.52 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const { errors } = require('celebrate');
const cors = require('cors');
const helmet = require('helmet');
const { routes } = require('./routes/index');
const errorHandler = require('./middlewares/errorHandler');
const NotFoundError = require('./erros/NotFoundError');
const { requestLogger, errorLogger } = require('./middlewares/logger');
const { DB_ADDRESS, PORT } = require('./config');
const limiter = require('./middlewares/limiter');
const app = express();
app.use(helmet());
app.disable('x-powered-by');
app.use(requestLogger);
app.use(limiter);
app.use(
cors({
origin: [
'http://localhost:3000',
'http://localhost:3001/api/movies',
'http://bakay.nomoredomains.work',
'https://bakay.nomoredomains.work',
'https://api.nomoreparties.co/beatfilm-movies',
],
credentials: true,
}),
);
app.use(bodyParser.json()); // сборка json-формата
app.use(bodyParser.urlencoded({ extended: true })); // прием web-страниц
app.use(routes);
app.use((req, res, next) => {
next(new NotFoundError('Запрашиваемый ресур не найден'));
});
app.use(errorLogger);
app.use(errors());
app.use(errorHandler);
async function main() {
try {
await mongoose.connect(DB_ADDRESS);
} catch (err) {
console.log(err);
}
app.listen(PORT, () => {
console.log(`Starting app on port ${PORT}`);
});
}
main();