generated from yandex-praktikum/express-mesto-gha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (32 loc) · 960 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
41
42
43
require('dotenv').config();
// IMPORT PACKAGES
const express = require('express');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const helmet = require('helmet');
const validationErrors = require('celebrate').errors;
// IMPORT ROUTES
const rootRouter = require('./routes/index');
// IMPORT MIDDLEWARES
const limiter = require('./middlewares/limiter');
const errors = require('./middlewares/errors');
// CONFIG VARIABLES
const PORT = process.env.PORT || 3000;
const DATABASE = process.env.DATABASE || 'mongodb://localhost:27017/mestodb';
// APP VARIABLES
const app = express();
// DATABASE CONNECT
mongoose.connect(DATABASE);
// PARSERS METHODS
app.use(express.json());
app.use(cookieParser());
// DEFENSE MIDDLEWARES
app.use(helmet());
app.use(limiter);
// ROUTES METHOD
app.use('/', rootRouter);
// ERRORS HANDLER MIDDLEWARES
app.use(validationErrors());
app.use(errors);
// SERVER LISTENER
app.listen(PORT);