mpp-server-dev2/index.js

72 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-04-12 23:29:02 +02:00
// dotenv
2021-03-20 20:12:38 +01:00
require('dotenv').config();
2021-04-12 23:29:02 +02:00
// call new Server
2020-04-07 09:55:16 +02:00
global.WebSocket = require('ws');
global.EventEmitter = require('events').EventEmitter;
global.fs = require('fs');
2021-04-12 23:29:02 +02:00
const AsyncConsole = require('asyncconsole');
2020-04-07 09:55:16 +02:00
2021-04-12 23:29:02 +02:00
global.isString = function(a) {
2020-04-07 09:55:16 +02:00
return typeof a === 'string';
}
2021-04-12 23:29:02 +02:00
global.isBool = function(a) {
2020-04-07 09:55:16 +02:00
return typeof a === 'boolean';
}
2021-04-12 23:29:02 +02:00
global.isObj = function(a) {
2020-04-07 09:55:16 +02:00
return typeof a === "object" && !Array.isArray(a) && a !== null;
}
2020-04-07 23:02:35 +02:00
let Server = require("./src/Server.js");
2020-04-07 09:55:16 +02:00
let config = require('./config');
global.SERVER = new Server(config);
2021-04-12 23:29:02 +02:00
2022-05-24 21:40:09 +02:00
// doesn't work with pm2
2021-04-12 23:29:02 +02:00
/*
2020-04-07 09:55:16 +02:00
let console = process.platform == 'win32' ? new AsyncConsole("", input => {
try {
console.log(JSON.stringify(eval(input)));
} catch(e) {
console.log(e.toString());
}
}) : {};
2021-04-12 23:29:02 +02:00
*/
2022-06-15 08:21:50 +02:00
// dev environment
if (config.hostDevFiles) {
2022-06-18 06:43:49 +02:00
let express_logger = new (require("./src/Logger"))("Express Server");
2022-06-15 08:21:50 +02:00
const express = require('express');
const app = express();
const path = require('path');
2022-06-18 06:43:49 +02:00
var http = require('http');
let dir = path.join(__dirname, 'mpp.hri7566.info');
app.use(express.static(path.join(__dirname, dir)));
app.get('*', (req, res, next) => {
let file = path.join(dir, req.path);
if (fs.existsSync(file)) {
res.sendFile(file);
} else {
res.sendFile(path.join(dir, 'index.html'));
}
2022-06-15 08:21:50 +02:00
});
2022-06-18 06:43:49 +02:00
const express_port = 8075;
http.createServer(app).listen(express_port);
2022-06-15 08:21:50 +02:00
}
if (config.enableMPPCloneBot) {
require('./mppclonebot');
}