-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.mjs
33 lines (24 loc) · 1.01 KB
/
app.mjs
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
import YAML from 'yamljs';
import dotenv from 'dotenv'
import express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import {checkJWT} from './middlewares/auth.middleware';
import swaggerUi from 'swagger-ui-express';
import authRouter from './routes/auth.route';
import messagesRouter from './routes/message.route';
import contactsRouter from './routes/contact.route';
import {resourceNotFoundException} from './middlewares/error.middleware';
const swaggerDocument = YAML.load('./swagger.yaml');
dotenv.config();
mongoose.set('useCreateIndex', true);
mongoose.connect(process.env.MONGO_DB_URI, {useNewUrlParser: true });
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/auth', authRouter);
app.use('/messages', checkJWT, messagesRouter);
app.use('/contacts', checkJWT, contactsRouter);
app.use(resourceNotFoundException);
export default app;