forked from goitacademy/nodejs-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (23 loc) · 900 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
const express = require('express')
const helmet = require('helmet')
const logger = require('morgan')
const cors = require('cors')
require('dotenv').config()
const usersRouter = require('./routes/api/users')
const contactsRouter = require('./routes/api/contacts')
const { errorHandler } = require('./helpers/errorHandler')
const app = express()
const formatsLogger = app.get('env') === 'development' ? 'dev' : 'short'
app.use(logger(formatsLogger))
app.use(helmet())
app.use(cors())
app.use(express.json({ limit: 1000 }))
app.use(express.static(process.env.PUBLIC_DIR))
app.use('/api/users', usersRouter)
app.use('/api/contacts', contactsRouter)
// Ответ на всех урлы, которые не заматчились
app.use((req, res) => {
res.status(404).json({ message: 'Not found' })
})
app.use(errorHandler) // Обработчик всех ошибок
module.exports = app