From 7fb303be23cfff5ac52684310184576d34099a3e Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 10 Feb 2025 21:17:50 +0800 Subject: [PATCH] resources: Serve source and static properly ... except that it won't run because of URL conflicts for now --- main.go | 2 ++ resources.go | 17 ++++++++++++++++- diff --git a/main.go b/main.go index 81657cdc8d1946b43e0bc9f1d7b5e580a90cbd52..6c69af45204b697f0785c3b7f58b02330fe5ded6 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,8 @@ if err != nil { clog.Fatal(1, "Serving static: "+err.Error()) } + serve_source() + http.HandleFunc("/{$}", handle_index) http.HandleFunc("/{category_name}/repos/{$}", handle_category_repos) http.HandleFunc("/{category_name}/repos/{repo_name}/{$}", handle_repo_index) diff --git a/resources.go b/resources.go index 860971ca5ae55eab257cce24f52a3c32ed5b1c2d..30b0de5b4222042a1ae6ef10da06b1698f64618f 100644 --- a/resources.go +++ b/resources.go @@ -7,6 +7,21 @@ "io/fs" "net/http" ) +//go:embed .gitignore LICENSE README.md +//go:embed *.go go.mod go.sum +//go:embed *.scfg +//go:embed static/* templates/* +var source_fs embed.FS + +func serve_source() { + http.Handle("/source/", + http.StripPrefix( + "/source/", + http.FileServer(http.FS(source_fs)), + ), + ) +} + //go:embed templates/* static/* var resources_fs embed.FS @@ -25,7 +40,7 @@ static_fs, err := fs.Sub(resources_fs, "static") if err != nil { return err } - http.Handle("/static/{name}", + http.Handle("/static/", http.StripPrefix( "/static/", http.FileServer(http.FS(static_fs)), -- 2.48.1