-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
56 lines (47 loc) · 1.57 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
/**
* app.js
* Use `app.js` to run your app.
* To start the server, run: `node app.js`.
*/
const express = require('express');
const cors = require('cors');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config({ path: '.env' });
global.__basedir = __dirname;
const postmanToOpenApi = require('postman-to-openapi');
const YAML = require('yamljs');
const swaggerUi = require('swagger-ui-express');
require('./database/mongodb/connection');
const app = express();
const corsOptions = { origin: process.env.ALLOW_ORIGIN, };
app.use(cors(corsOptions));
//template engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
/*
* response handler middleware
* app.use(require('./services/utility/response'));
*/
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(require('./routes'));
//swagger Documentation
postmanToOpenApi('postman/CC-Template.postman_collection.json', path.join('postman/swagger.yml'), { defaultTag: 'General' }).then(data => {
let result = YAML.load('postman/swagger.yml');
result.servers[0].url = '/';
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(result));
}).catch(e => {
console.log('Swagger Generation stopped due to some error');
});
app.get('/', (req, res) => {
res.render('index');
});
if (process.env.NODE_ENV !== 'test') {
app.listen(process.env.PORT, process.env.HOST, () => {
console.log(`your application is running on ${process.env.HOST}:${process.env.PORT}`);
});
} else {
module.exports = app;
}