generated from yandex-praktikum/express-mesto-gha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (47 loc) · 1.48 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const rateLimit = require('express-rate-limit');
const { errors } = require('celebrate');
const { login, createUser } = require('./controllers/user');
const authMiddleware = require('./middlewares/auth');
const errorMiddleware = require('./middlewares/errorMiddleware');
const NotFoundError = require('./errors/NotFoundError');
const SignUpValidation = require('./middlewares/validations/SignUpValidation');
const SignInValidation = require('./middlewares/validations/SignInValidation');
const { PORT = 3000 } = process.env;
const app = express();
app.use(rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
standardHeaders: true,
legacyHeaders: false,
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
mongoose.connect('mongodb://localhost:27017/mestodb', {
useNewUrlParser: true,
});
app.post(
'/signin',
SignInValidation,
login,
);
app.post(
'/signup',
SignUpValidation,
createUser,
);
app.use(authMiddleware);
app.use('/users', require('./routes/user'));
app.use('/cards', require('./routes/card'));
app.use((req, res, next) => {
next(new NotFoundError('Такого роута не существует'));
});
app.use(errors());
app.use(errorMiddleware);
app.listen(PORT, () => {
console.log('Сервер запущен на порте 3000');
});