This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
123 lines (107 loc) · 3.05 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* app.js
* @type {createApplication}
*/
const express = require('express');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const app = express();
const path = require('path');
const pathManager = require('./app/core/path-manager');
const config = require('./app/core/eqemu-config-service');
const authService = require('./app/core/auth-service');
const database = require('./app/core/database');
const hotReloadService = require('./app/core/hot-reload-service');
const fileEventWatcher = require('./app/core/file-event-watcher');
const debug = require('debug')('eqemu-admin:app');
/**
* Init services
*/
pathManager.init(__dirname);
config.init();
authService.initializeAppKey();
authService.initializeAdminPasswordIfNotSet();
/**
* Express
*/
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
/**
* For Development
* @type {any}
*/
var cors = require('cors')
app.use(
cors(
{
origin: [
'http://localhost:8080',
'http://192.168.98.200:8080',
'http://192.168.65.229:8080',
'http://192.168.65.130:8080',
'http://localhost:8081',
'http://docker:8080',
'http://localhost:5000'
],
exposedHeaders: ['Content-Disposition']
}
)
);
app.use(authService.handleApiRoutes());
/**
* Routes
*/
app.use('/download', require('./app/routes/download'));
/**
* API
*/
app.use('/api/v1/dashboard/stats', require('./app/routes/api/dashboard/stats'));
app.use('/api/v1/world/', require('./app/routes/api/world/world'));
app.use('/api/v1/zoneserver', require('./app/routes/api/zoneserver'));
app.use('/api/v1/zoneserver/netstat', require('./app/routes/api/zoneserver/netstat'));
app.use('/api/v1/server', require('./app/routes/api/server'));
app.use('/api/v1/auth', require('./app/routes/api/auth/auth'));
app.use('/api/v1/admin', require('./app/routes/api/admin'));
app.use('/api/v1/backup', require('./app/routes/api/backup/backup'));
app.use('/api/v1/download', require('./app/routes/download'));
/**
* Serve Vue SPA
*/
app.use(express.static(path.join(__dirname, 'public'), { maxAge: '1y', etag: true, lastModified: true }));
/**
* After other routes are not found
*/
app.get('*', function (req, res, next) {
res.sendFile(path.join(__dirname, 'public/index.html'))
});
module.exports = app;
/**
* Database
*/
async () => {
database.init();
};
/**
* Hot Reload Service
*/
hotReloadService.init();
/**
* NetStat Listeners
*/
const netstatListener = require('./app/core/netstat-listener');
setInterval(function () {
netstatListener.prune();
netstatListener.listen();
}, 1000);
/**
* Watchdog supervisor for launcher
*/
const serverProcessManager = use('/app/core/server-process-manager');
serverProcessManager.checkIfLauncherNeedsToBeRevived();
setInterval(() => {
debug('[www] Running watchdog');
serverProcessManager.checkIfLauncherNeedsToBeRevived();
}, 60 * 1000);
fileEventWatcher.watchCrashLogs();