diff options
| -rw-r--r-- | roseh.moe.go | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index df86f2d..8ca8872 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -95,34 +95,24 @@ func favicon(w http.ResponseWriter, r *http.Request) { func main() { flag.Parse() - mux := http.NewServeMux() - mux.HandleFunc("/pong", pong) + http.HandleFunc("GET /pong", pong) jellyfinURL, err := url.Parse("http://localhost:8096") if err != nil { log.Fatalf("Jellyfin URL: %s", err) } - mux.Handle("/cinema/", httputil.NewSingleHostReverseProxy(jellyfinURL)) - mux.HandleFunc("/static/", static) - mux.HandleFunc("/favicon.ico", favicon) - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/" { - index(w, r) - } else { - notFound(w, r) - } - }) + http.Handle("/cinema/", httputil.NewSingleHostReverseProxy(jellyfinURL)) + http.HandleFunc("GET /static/", static) + http.HandleFunc("GET /favicon.ico", favicon) + http.HandleFunc("GET /{$}", index) + notFoundMux := http.NewServeMux() + notFoundMux.HandleFunc("GET /", notFound) + http.Handle("/", notFoundMux) - httpServer := http.Server{ - Addr: fmt.Sprintf(":%d", *port), - Handler: mux, - ReadTimeout: 5 * time.Second, - WriteTimeout: 5 * time.Second, - } - - log.Printf("Listening on %q", httpServer.Addr) + addr := fmt.Sprintf(":%d", *port) + log.Printf("Listening on %q", addr) if *https { - log.Fatal(httpServer.ListenAndServeTLS("/var/lib/acme/roseh.moe/cert.pem", "/var/lib/acme/roseh.moe/key.pem")) + log.Fatal(http.ListenAndServeTLS(addr, "/var/lib/acme/roseh.moe/cert.pem", "/var/lib/acme/roseh.moe/key.pem", nil)) } else { - log.Fatal(httpServer.ListenAndServe()) + log.Fatal(http.ListenAndServe(addr, nil)) } } |
