-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.js
42 lines (31 loc) · 1.14 KB
/
http.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
const express = require("express")
const path = require("path")
const version = require("./package.json").version
const config = require("./loadconfig")
const host = "localhost"
let app = express()
app.use((req, res, next) => {
res.header("Cache-Control", "no-cache")
res.setHeader("X-Powered-By", `Boltobserv ${version} <github.com/boltgolt/boltobserv>`)
next()
})
app.get("/favicon.ico", (req, res) => { res.sendFile(path.join(__dirname, "img", "favicon.ico")) })
for (let dir of ["css", "renderers", "img", "maps"]) {
app.use(`/${dir}`, express.static(path.join(__dirname, dir)))
}
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"))
})
function handleCheck(req, res) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
res.json({
"type": "boltgolt/boltobserv",
"version": version,
"socket": config.browser.ports.socket
})
}
app.options("/doorknock", handleCheck)
app.get("/doorknock", handleCheck)
app.listen(config.browser.ports.static)
console.info(`Browser view enabled at http://${host}:${config.browser.ports.static}`)