-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher.js
59 lines (58 loc) · 1.64 KB
/
launcher.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
const serverCommands = require('./serverCommands'),
startServer = serverCommands.startServer,
quitServer = serverCommands.quitServer,
restartServer = serverCommands.restartServer,
checkIfRunning = serverCommands.checkIfRunning,
express = require('express'),
app = express(),
pm2 = require('pm2'),
path = require('path')
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
})
app.get('/startServer', (req, res) => {
checkIfRunning().then(() => {
res.send("running")
}).catch(() => {
const subdomain = 'pianoserver',
port = 8081
startServer(subdomain, port).then(() => {
res.send('started')
}).catch(() => {
res.send('failed')
})
})
})
app.get('/restartServer', (req, res) => {
checkIfRunning().then(() => {
restartServer().then(() => {
res.send('restarting')
}).catch(() => {
res.send('failed')
})
}).catch(() => {
res.send('not running')
})
})
app.get('/quitServer', (req, res) => {
checkIfRunning().then(() => {
quitServer().then(() => {
res.send('quitted')
}).catch(() => {
res.send('failed')
})
}).catch(() => {
res.send('not running')
})
})
app.get('/serverStatus', (req, res) => {
checkIfRunning().then(() => {
res.send('running')
}).catch(() => {
res.send('not running')
})
})
app.get('/', (req, res) => res.send('running'))
app.listen(8082)