summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--roseh.moe.go45
1 files changed, 28 insertions, 17 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index d69ec06..4b61194 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -5,10 +5,12 @@ import (
"flag"
"fmt"
"html/template"
+ "io"
"log"
"net/http"
"net/http/httputil"
"net/url"
+ "strings"
"time"
)
@@ -17,19 +19,6 @@ var (
https = flag.Bool("https", false, "use https")
)
-func index(w http.ResponseWriter, _ *http.Request) {
- fmt.Fprint(w, `<!DOCTYPE html>
-<html lang="en">
- <head>
- <title>roseh.moe</title>
- </head>
- <body>
- <p>Hello world</p>
- </body>
-</html>
-`)
-}
-
//go:embed templates/404.html.template
var notFoundString string
@@ -41,13 +30,35 @@ func notFound(w http.ResponseWriter, r *http.Request) {
Path string
}
if err := notFoundTemplate.Execute(w, args{Path: r.URL.Path}); err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
+ log.Printf("Warning: notFound: %s", err)
+ }
+}
+
+//go:embed templates/index.html.template
+var indexString string
+
+var indexTemplate = template.Must(template.New("index").Parse(indexString))
+
+func index(w http.ResponseWriter, _ *http.Request) {
+ if err := indexTemplate.Execute(w, nil); err != nil {
+ log.Printf("Warning: index: %s", err)
}
}
//go:embed static
-var static embed.FS
+var staticFiles embed.FS
+
+func static(w http.ResponseWriter, r *http.Request) {
+ f, err := staticFiles.Open(strings.TrimPrefix(r.URL.Path, "/"))
+ if err != nil {
+ notFound(w, r)
+ return
+ }
+ defer f.Close()
+ if _, err := io.Copy(w, f); err != nil {
+ log.Printf("Warning: static: %s", err)
+ }
+}
func main() {
flag.Parse()
@@ -58,7 +69,7 @@ func main() {
log.Fatalf("Jellyfin URL: %s", err)
}
mux.Handle("/cinema/", httputil.NewSingleHostReverseProxy(jellyfinURL))
- mux.Handle("/static/", http.FileServerFS(static))
+ mux.HandleFunc("/static/", static)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
index(w, r)