summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-10-17 10:46:09 -0700
committerRose Hogenson <rosehogenson@posteo.net>2024-10-17 10:46:09 -0700
commitff88b8a8c0da46edbc554982408d1be6a17e4c64 (patch)
treeeff1b2ad2495a143fcf4e9bdad15a4af08862758 /roseh.moe.go
downloadroseh.moe-ff88b8a8c0da46edbc554982408d1be6a17e4c64.tar.zst
Initial commit
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go60
1 files changed, 60 insertions, 0 deletions
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))
+ }
+}