const express = require('express'); const app = express(); const path = require('path'); const logger = require('morgan'); const cors = require('cors'); const helmet = require('helmet'); const chatsRouter = require('./routes/chats'); const messagesRouter = require('./routes/messages'); const contactsRouter = require('./routes/contacts'); const userRoute = require('./routes/user'); const DIR_STATIC = process.env.DIR_STATIC; const formatsLogger = app.get('env') === 'development' ? 'dev' : 'short'; app.use(helmet()); app.use(logger(formatsLogger)); app.use(cors()); app.use(express.json()); app.use(express.static(path.join(__dirname, DIR_STATIC))); app.use('/api/chats', chatsRouter); app.use('/api/messages', messagesRouter); app.use('/api/contacts', contactsRouter); app.use('/api', userRoute); app.use((_req, res) => res.status(404).json({ message: 'Not found' })); app.use((err, _req, res, _next) => res.status(500).json({ message: err.message }) ); module.exports = app;