-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (26 loc) · 858 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
const express = require('express');
const { PORT = 3000 } = process.env;
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const mongoose = require('mongoose');
const { MONGO_URL } = require('./config');
const cors = require('./middlewares/cors');
const limiter = require('./middlewares/rate-limiter');
const errorHandler = require('./middlewares/error-handler');
const { requestLogger, errorLogger } = require('./middlewares/logger');
const routes = require('./routes');
const app = express();
app.use(bodyParser.json());
app.use(cookieParser());
mongoose.connect(
MONGO_URL,
{ useNewUrlParser: true },
() => console.log('База данных загружена'),
);
app.use(cors);
app.use(requestLogger);
app.use(limiter);
app.use(routes);
app.use(errorLogger);
app.use(errorHandler);
app.listen(PORT);