-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
30 lines (25 loc) · 771 Bytes
/
index.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
const exp = require('express')
const exe = require('child_process').exec
const nfs = require('fs')
const app = exp()
app.use(exp.static('web'))
app.use(exp.json())
app.get('/config', (req, res) => {
res.sendFile(__dirname + '/config.json')
})
app.post('/config', (req, res) => {
nfs.writeFile('./config.json', JSON.stringify(req.body, null, " "), err => {
if (err) {
console.error(err)
res.status(500).send('Could not save config.')
}
exe('reboot', err => {
if (err) {
console.error(err)
res.status(500).send('Could not reboot to apply config. Retry or reboot manually.')
}
res.status(200).send('New config applied; rebooting for changes to take effect...')
})
})
})
app.listen(80, console.error)