-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 1.1 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
const doT = require('dot')
const fs = require('fs')
const getGoProPassword = require('./gopro').getGoProPassword
const getStreamingData = require('./gopro').getStreamingData
const http = require('http')
const sendStartStopCmd = require('./gopro').sendStartStopCmd
const tessel = require('tessel')
let GoProPassword = ''
getGoProPassword()
.then((pwd) => GoProPassword = pwd)
.catch((err) => {
setTimeout(() => {
getGoProPassword()
}, 5000)
})
const server = http.createServer((request, response) => {
const {url} = request
if (url === '/') {
showIndex(request, response)
} else if (url.match(/^\/bacpac\/.*/)) {
sendStartStopCmd(request, response)
} else {
getStreamingData(request, response)
}
})
const showIndex = (request, response) => {
response.writeHead(200, {"Content-Type": "text/html"})
fs.readFile(__dirname + '/index.html', (err, content) => {
if (err) {
throw err
}
const tempFn = doT.template(content)
const resultText = tempFn({host: request.headers.host, gopropwd: GoProPassword})
response.end(resultText)
})
}
server.listen(80)