forked from AmericanAirlines/AA-Mock-Engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (45 loc) · 1.51 KB
/
app.js
File metadata and controls
61 lines (45 loc) · 1.51 KB
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
57
58
59
60
61
'use strict';
require("dotenv").config();
const express = require('express');
const bodyParser = require('body-parser');
const SwaggerExpress = require('swagger-express-mw');
const SwaggerUI = require('swagger-tools/middleware/swagger-ui');
const _ = require('lodash');
const mongoHelper = require('./api/helpers/mongoHelper');
const app = express();
const port = process.env.PORT || 3030;
module.exports = app; // for testing
let appRoot = __dirname;
global.appRoot = appRoot;
let config = {
appRoot: appRoot // required config
};
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
// install middleware
app.use(SwaggerUI(swaggerExpress.runner.swagger));
swaggerExpress.register(app);
app.listen(port);
console.log("App listening on ", port);
// if (swaggerExpress.runner.swagger.paths['/hello']) {
// console.log('Listening on', port, '(Try: curl http://127.0.0.1:' + port + '/hello?name=Scott)');
// }
});
start().catch(function(err) {
console.log("Something went wrong... ", err);
});
function start() {
var promises = [];
// Do all async setup here, example:
// let someAsyncCall = something();
// promises.push(someAsyncCall);
promises.push(mongoHelper.connectToDb());
return Promise.all(promises).then(function(){
console.log("\n\nSetup complete!");
});
}
// ~~~~~ ROUTING ~~~~~
app.get('/', function(req, res) {
// Redirect all traffic to docs
res.redirect('/docs');
});