-
Notifications
You must be signed in to change notification settings - Fork 6
/
startUp.js
76 lines (61 loc) · 2.41 KB
/
startUp.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function () {
"use strict";
let express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
config = require('./config');
module.exports = {
start: function (done) {
logger.success('Application started successfully');
// set the database
database.connect(function(db){
/*The DB connection is open*/
db.on('open', function () {
/*Perform operations that require DB connection*/
//start hashPokemonGo module
const listener = require(__base + 'app/controllers/filler/hashPokemonGo');
listener.insertToDb(function () {
return;
});
});
});
//Setup application
var app = express();
// Add parser to get the data from a POST
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
//router setup
var router = express.Router();
// for every request
router.use(function (req, res, next) {
logger.info('Request incoming: ' + req.url);
//Allow all GET requests as these do not modify data and we want users to be able to see that basic stuff
if (req.method === 'GET') {
return next();
}
});
//cors support for all routes
app.use(cors({
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
}));
//routes inclusion
require(__base + 'routes')(app, router);
// Redirect default route / to the API documentation
app.get('/', function (req, res) {
return res.redirect('/doc');
});
// prefix for all routes
app.use('/api', router);
// Render the api documentation
app.use('/doc', express.static('apidoc'));
//listening for requests
var port = config.server.port || 8080; //a default port if the config file does not contain it
app.listen(port);
logger.info('Listening on port ' + port);
},
stop: function (done) {
logger.info('Application stopped');
}
};
}());