-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (83 loc) · 2.57 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
// const { exec } = require("child_process");
// const system_stats = require('./modules/system-stats-module');
const express = require('express');
const bodyParser = require('body-parser');
const sys = require('./services/system_stats_service');
const minecraft = require('./services/minecraft_service');
const valheim = require('./services/valheim_service');
const factorio = require('./services/factorio_service');
const app = express();
app.use(bodyParser.json({ extended: true }));
/*
API/SERVER FUNCTIONS
*/
app.get('/server', async function(req, res) {
// Access the provided 'page' and 'limt' query parameters
let time = req.query.time;
let sys_info = sys.sysinfo(time*12);
res.send('info = '+sys_info)
});
app.get('/minecraft', async function(req, res) {
// Access the provided 'page' and 'limt' query parameters
minecraft.run();
res.send('ran');
});
app.get('/minecraft/stop', async function(req, res) {
// Access the provided 'page' and 'limt' query parameters
minecraft.stop();
res.send('ran');
});
app.post('/valheim',(req, res) =>{
let requestbody = req.body;
console.debug('request ',req.body);
if(requestbody["apikey"]==='zainisafatneek'){
switch (requestbody["request"]){
case "start":
valheim.run();
res.sendStatus(200);
break;
case "stop":
valheim.stop();
res.sendStatus(200);
break;
case "status":
let valheim_status = valheim.status();
res.send(valheim_status);
break;
default:
res.sendStatus(405);
}
}
else{
res.sendStatus(401)
}
});
app.post('/factorio',(req, res) =>{
let requestbody = req.body;
console.debug('request ',req.body);
if(requestbody["apikey"]==='zainisafatneek'){
switch (requestbody["request"]){
case "start":
factorio.run();
res.sendStatus(200);
break;
case "stop":
factorio.stop();
res.sendStatus(200);
break;
case "status":
let factorio_status = factorio.status();
res.send(factorio_status);
break;
default:
res.sendStatus(405);
}
}
else{
res.sendStatus(401)
}
});
app.listen(process.env.PORT || 3000, () => console.log(`App available on http://localhost:3000`))
/*
INTERNAL FUNCTIONS
*/