-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
61 lines (52 loc) · 1.29 KB
/
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
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
var path = require('path')
var util = require('util')
var express = require('express')
var address = require('network-address')
var updateNotifier = require('update-notifier')
var powerOff = require('power-off')
var sleepMode = require('sleep-mode')
var pkg = require('./package.json')
var app = express()
var notifier = updateNotifier({ pkg: pkg })
app.use(express.static(path.join(__dirname, 'public')))
app.delete('/', function (req, res) {
res.end()
util.log('exit')
process.exit()
})
app.post('/power-off', function (req, res) {
powerOff(function (err, stderr, stdout) {
if (err) {
util.log(err)
res.status(500).json({ error: 'Can\'t run power-off' })
} else {
res.end()
}
})
})
app.post('/sleep', function (req, res) {
sleepMode(function (err, stderr, stdout) {
if (err) {
util.log(err)
res.status(500).json({ error: 'Can\'t run sleep' })
} else {
res.end()
}
})
})
app.get('/address', function (req, res) {
res.json({ address: address() })
})
app.get('/update', function (req, res) {
updateNotifier({
pkg: pkg,
callback: function (err, update) {
if (err) return res.json({})
res.json(update)
}
})
})
var port = 5709
app.listen(port, function () {
util.log('stop-server listening on port ' + port)
})