forked from proxyz100/travelAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (25 loc) · 924 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
require('dotenv').config();
const express = require('express');
const sequelize = require('./config/db');
const routes = require('./routes/index.routes');
const auth = require('./config/auth.js');
const swaggerOptions = require('./config/swagger');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUI = require('swagger-ui-express');
const app = express();
app.use(express.json());
// Ask for the optional middleware before we use the routes
app.use(auth.optional); // global middle ware
app.use('/', routes);
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use('/docs', swaggerUI.serve, swaggerUI.setup(swaggerDocs));
try {
sequelize.authenticate();
sequelize.sync();
console.log('Connected to DB');
} catch (error) {
console.log('Unable to connect to DB: ', error);
}
app.listen(process.env['PORT'] || 4000, () => {
console.log("listening on port " + process.env['PORT']);
});