diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-17 10:46:09 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-17 10:46:09 -0700 |
| commit | ff88b8a8c0da46edbc554982408d1be6a17e4c64 (patch) | |
| tree | eff1b2ad2495a143fcf4e9bdad15a4af08862758 | |
| download | roseh.moe-ff88b8a8c0da46edbc554982408d1be6a17e4c64.tar.zst | |
Initial commit
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | roseh.moe.go | 60 |
2 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,3 @@ +module gitlab.com/rhogenson/roseh.moe + +go 1.23.2 diff --git a/roseh.moe.go b/roseh.moe.go new file mode 100644 index 0000000..42c854a --- /dev/null +++ b/roseh.moe.go @@ -0,0 +1,60 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net/http" + "net/http/httputil" + "net/url" +) + +var ( + port = flag.Int("port", 42069, "port to listen on") + https = flag.Bool("https", false, "use https") +) + +type server struct { + jellyfinProxy *httputil.ReverseProxy +} + +func (*server) 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> +`) +} + +func (s *server) cinema(w http.ResponseWriter, r *http.Request) { + s.jellyfinProxy.ServeHTTP(w, r) +} + +func main() { + flag.Parse() + + jellyfinURL, err := url.Parse("http://localhost:8096") + if err != nil { + log.Fatalf("Jellyfin URL: %s", err) + } + + s := &server{ + jellyfinProxy: httputil.NewSingleHostReverseProxy(jellyfinURL), + } + http.HandleFunc("GET /{$}", s.index) + http.HandleFunc("/cinema", s.cinema) + http.HandleFunc("/cinema/", s.cinema) + + addr := fmt.Sprintf(":%d", *port) + log.Printf("Listening on %q", addr) + if *https { + log.Fatal(http.ListenAndServeTLS(addr, "/var/lib/acme/roseh.moe/cert.pem", "/var/lib/acme/roseh.moe/key.pem", nil)) + } else { + log.Fatal(http.ListenAndServe(addr, nil)) + } +} |
