-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
58 lines (48 loc) · 1.19 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
package main
import (
"embed"
"io/fs"
"log"
"net/http"
"github.com/gorilla/mux"
)
// content holds our static web server content.
//go:embed web/*
var content embed.FS
type Router struct {
*mux.Router
}
func NewRouter() *Router {
r := mux.NewRouter()
webContent, err := fs.Sub(content, "web")
if err != nil {
panic("No web content found")
}
fs := http.FileServer(http.FS(webContent))
r.Handle("/", fs)
r.Handle("/healthz", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK\n"))
}))
r.Handle("/index.html", fs)
r.Handle("/favicon.ico", fs)
r.Handle("/main.css", fs)
r.Handle("/api/whoami", fs)
r.Handle("/api/snapshot/new", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Tilt Cloud is deprecated", http.StatusGone)
}))
r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
})
return &Router{
Router: r,
}
}
func main() {
http.Handle("/", NewRouter())
log.Println("Serving on port 10450")
err := http.ListenAndServe(":10450", nil)
if err != nil {
log.Fatalf("Server exited with: %v", err)
}
}