This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (64 loc) · 2.14 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const bodyParser = require('body-parser');
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const models = require('./models/index');
// Add timestamps to logs:
require('console-stamp')(console);
const { expressError } = require('./utils/error_handlers');
const routes = require('./routes/index');
const port = 9500;
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
models.sequelize
.sync({})
.then(async () => {
// Initialize DB data
// await require('./initialization/initialize')();
server.listen(port, () => {
console.log(`server listening in port ${port}`);
// const cron = require('./cron/1.get_runs'); // (for testing)
if (process.env.ENV !== 'development') {
const cron = require('./cron/1.get_runs');
}
// const dqm_gui_pinging = require('./cron_datasets/2.ping_dqm_gui');
// const dbs_pinging = require('./cron_datasets/2.ping_dbs');
});
// 100 minute timout to server
server.timeout = 100 * 60 * 1000;
app.use((req, res, next) => {
req.io = io;
next();
});
io.on('connect', (socket) => {
console.log('connection established for new client');
});
// For use in json_creation:
app.use(morgan('dev'));
app.use(cors());
app.use(bodyParser.json({ limit: '400mb' }));
app.use(bodyParser.urlencoded({ limit: '400mb', extended: true }));
// Log the user
app.use('*', (req, res, next) => {
if (process.env.NODE_ENV === 'production') {
console.log(req.get('displayname'));
}
next();
});
routes(app);
// We add socket.io to the request
// Make errors appear as json to the client
app.use(expressError);
// Catch Application breaking error and label it here:
process.on('uncaughtException', (err) => {
console.log('CRITICAL ERROR: ', err);
});
// Catch Promise error and label it here:
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Promise Rejection at:', p, 'reason:', reason);
});
})
.catch((err) => {
console.log(err);
});