-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
67 lines (57 loc) · 1.58 KB
/
main.go
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
62
63
64
65
66
67
package main
import (
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/grandcat/zeroconf"
)
var mdns *zeroconf.Server
var wwwRoot string
var development bool
func main() {
development = (os.Getenv("DEVELOPMENT") == "True")
if development && os.Getenv("FRONTEND_PATH") != "" {
wwwRoot = os.Getenv("FRONTEND_PATH") + "/landing-page/dist/"
} else if development {
wwwRoot = "./rootfs/usr/share/www/"
} else {
wwwRoot = "/usr/share/www/"
}
http.HandleFunc("/", httpIndex)
http.HandleFunc("/api/", httpUnauthorized)
http.HandleFunc("/auth/token", httpBad)
http.HandleFunc("/observer/logs", httpLogs)
http.HandleFunc("/supervisor/supervisor/logs", httpSupervisorProxy)
http.HandleFunc("/supervisor/supervisor/logs/follow", httpSupervisorProxy)
http.HandleFunc("/supervisor/resolution/", httpSupervisorProxy)
http.HandleFunc("/supervisor/network/", httpSupervisorProxy)
// Serve static help files
staticFiles := http.FileServer(http.Dir(wwwRoot))
http.Handle("/static/", staticFiles)
http.Handle("/frontend_es5/", staticFiles)
http.Handle("/frontend_latest/", staticFiles)
// Start mDNS broadcast
log.Print("Start mDNS broadcast")
publishHomeAssistant()
defer mdns.Shutdown()
// Run webserver
go func() {
log.Print("Start webserver on http://0.0.0.0:8123")
if err := http.ListenAndServe(":8123", nil); err != nil {
log.Fatal(err)
}
}()
signalChannel := make(chan os.Signal, 2)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
for {
sig := <-signalChannel
switch sig {
case os.Interrupt:
return
case syscall.SIGTERM:
return
}
}
}