forked from EdgeApp/edge-react-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggingServer.js
57 lines (47 loc) · 1.26 KB
/
loggingServer.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
/* eslint-disable flowtype/require-valid-file-annotation */
const os = require('os')
const express = require('express')
const bodyParser = require('body-parser')
const jsonfile = require('jsonfile')
const ifaces = os.networkInterfaces()
const PORT = 8080
const envFile = './env.json'
let address = ''
let envJSON = { LOG_SERVER: {} }
try {
envJSON = jsonfile.readFileSync(envFile)
} catch (e) {
console.log(e)
}
try {
// Get Local Host Address
Object.keys(ifaces).forEach(function (ifname) {
let found = false
ifaces[ifname].forEach(function (iface) {
if (iface.family !== 'IPv4' || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return
}
if (found) return
address = iface.address
found = true
})
})
// Set env.json with correct path
envJSON.LOG_SERVER = {
host: `http://${address}`,
port: `${PORT}`
}
jsonfile.writeFileSync(envFile, envJSON)
} catch (e) {
console.log(e)
}
// Run the logging server
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.post('/log', function (req, res) {
if (req.body && req.body.data) console.log(req.body.data.toString())
res.sendStatus(200)
})
app.listen(PORT)