-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (50 loc) · 1.39 KB
/
server.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
const express = require('express')
const bodyParser = require('body-parser')
const boxen = require('boxen');
const app = express()
const mongodb = require('./databases/mongoDatabase')
const CheckExecutor = require('./checkExecutor/CheckExecutor');
const sqlDb = require('./databases/sqlDatabase');
// Config
const config = require('./config/config.json')
// Startup log
console.log(boxen('CM API', {
padding: {
left: 20,
right: 20,
top: 1,
bottom: 1
},
margin: 1,
borderStyle: 'double'
}))
// Use
app.use(bodyParser.json())
//CORS
var cors = require('cors')
app.use(cors())
// Route files
const authRoutes = require('./routes/auth.routes')
const checkRoutes = require('./routes/check.routes')
app.all("*", function(req, res, next)
{
console.log(req.method + " " + req.url);
next();
});
// Routes
app.get('/', (req, res) => res.send('Welcome to the CM API!'))
app.use('/api/auth', authRoutes)
app.use('/api/checks', checkRoutes)
sqlDb.getConnection();
CheckExecutor.getAllChecks();
let isInTest = typeof global.it === 'function';
if(!isInTest) CheckExecutor.executeChecksOnInterval(5);
// Listen on port
var server = app.listen(process.env.PORT || config.port, function () {
var host = server.address().address
var port = server.address().port
console.log("Express: Listening to Socket: http://localhost:" + port)
})
module.exports = {
app
}