-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (44 loc) · 1.09 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
'use strict'
// -- imports
const minimist = require('minimist')
const express = require('express')
const path = require('path')
// -- routes
var Actions = require('./actions.js')
var actions = new Actions('./data/usm.xml')
// -- config
var args = minimist(process.argv.slice(2), {
string: ['port'],
alias: {
p: 'port'
},
default: {
port: 8080
}
})
// -- publish web interface
var app = express()
app.use(express.static(path.join(__dirname, "web")))
app.get("/", (request, result) => {
result.sendFile(path.join(__dirname, "web", "index.html"))
})
app.get("/data", (req, res) => {
actions.getJSON()
.then((result) => {
return res.status(200).send({
msg: 'ok',
data: result
})
})
.catch((error) => {
return res.status(500).send({
msg: 'error',
error: error
})
})
})
app.listen(args.port, () => {
console.log("ui listening on port " + args.port)
}).on('error', function (error) {
console.error(error)
})