From 5e50fede9a1615aa444dfc06cdee79258fd2e852 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sat, 2 May 2026 03:15:07 +0900 Subject: [PATCH] cmd/pkgserver: move ui internal This avoids inadvertently exporting a go package. This change also cleans up generate layout. Signed-off-by: Ophestra --- .gitignore | 2 +- cmd/pkgserver/{ => internal}/ui/index.html | 0 cmd/pkgserver/{ => internal}/ui/index.ts | 0 .../{ui/static => internal/ui}/style.css | 0 cmd/pkgserver/{ => internal}/ui/tsconfig.json | 0 cmd/pkgserver/internal/ui/ui.go | 21 +++++++++++ cmd/pkgserver/internal/ui/ui_full.go | 10 ++++++ cmd/pkgserver/{ => internal/ui}/ui_stub.go | 2 +- cmd/pkgserver/main.go | 3 +- cmd/pkgserver/ui.go | 33 ------------------ cmd/pkgserver/ui/static/favicon.ico | Bin 16958 -> 0 bytes cmd/pkgserver/ui_full.go | 9 ----- 12 files changed, 35 insertions(+), 45 deletions(-) rename cmd/pkgserver/{ => internal}/ui/index.html (100%) rename cmd/pkgserver/{ => internal}/ui/index.ts (100%) rename cmd/pkgserver/{ui/static => internal/ui}/style.css (100%) rename cmd/pkgserver/{ => internal}/ui/tsconfig.json (100%) create mode 100644 cmd/pkgserver/internal/ui/ui.go create mode 100644 cmd/pkgserver/internal/ui/ui_full.go rename cmd/pkgserver/{ => internal/ui}/ui_stub.go (84%) delete mode 100644 cmd/pkgserver/ui.go delete mode 100644 cmd/pkgserver/ui/static/favicon.ico delete mode 100644 cmd/pkgserver/ui_full.go diff --git a/.gitignore b/.gitignore index 8325f1cb..488373ff 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ # go generate /cmd/hakurei/LICENSE -/cmd/pkgserver/ui/static/*.js +/cmd/pkgserver/internal/ui/static /internal/pkg/testdata/testtool /internal/rosa/hakurei_current.tar.gz diff --git a/cmd/pkgserver/ui/index.html b/cmd/pkgserver/internal/ui/index.html similarity index 100% rename from cmd/pkgserver/ui/index.html rename to cmd/pkgserver/internal/ui/index.html diff --git a/cmd/pkgserver/ui/index.ts b/cmd/pkgserver/internal/ui/index.ts similarity index 100% rename from cmd/pkgserver/ui/index.ts rename to cmd/pkgserver/internal/ui/index.ts diff --git a/cmd/pkgserver/ui/static/style.css b/cmd/pkgserver/internal/ui/style.css similarity index 100% rename from cmd/pkgserver/ui/static/style.css rename to cmd/pkgserver/internal/ui/style.css diff --git a/cmd/pkgserver/ui/tsconfig.json b/cmd/pkgserver/internal/ui/tsconfig.json similarity index 100% rename from cmd/pkgserver/ui/tsconfig.json rename to cmd/pkgserver/internal/ui/tsconfig.json diff --git a/cmd/pkgserver/internal/ui/ui.go b/cmd/pkgserver/internal/ui/ui.go new file mode 100644 index 00000000..fbee1b7f --- /dev/null +++ b/cmd/pkgserver/internal/ui/ui.go @@ -0,0 +1,21 @@ +// Package ui holds the static web UI. +package ui + +import "net/http" + +func serveWebUI(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + w.Header().Set("Pragma", "no-cache") + w.Header().Set("Expires", "0") + w.Header().Set("X-Content-Type-Options", "nosniff") + w.Header().Set("X-XSS-Protection", "1") + w.Header().Set("X-Frame-Options", "DENY") + + http.ServeFileFS(w, r, content, "static/index.html") +} + +// Register arranges for mux to serve the embedded frontend. +func Register(mux *http.ServeMux) { + mux.Handle("GET /", http.FileServer(http.FS(content))) + mux.HandleFunc("GET /{$}", serveWebUI) +} diff --git a/cmd/pkgserver/internal/ui/ui_full.go b/cmd/pkgserver/internal/ui/ui_full.go new file mode 100644 index 00000000..232f5e65 --- /dev/null +++ b/cmd/pkgserver/internal/ui/ui_full.go @@ -0,0 +1,10 @@ +//go:build frontend + +package ui + +import "embed" + +//go:generate tsc +//go:generate cp index.html style.css static +//go:embed static +var content embed.FS diff --git a/cmd/pkgserver/ui_stub.go b/cmd/pkgserver/internal/ui/ui_stub.go similarity index 84% rename from cmd/pkgserver/ui_stub.go rename to cmd/pkgserver/internal/ui/ui_stub.go index bdd691da..fea38491 100644 --- a/cmd/pkgserver/ui_stub.go +++ b/cmd/pkgserver/internal/ui/ui_stub.go @@ -1,6 +1,6 @@ //go:build !frontend -package main +package ui import "testing/fstest" diff --git a/cmd/pkgserver/main.go b/cmd/pkgserver/main.go index 82165a03..6889dfe1 100644 --- a/cmd/pkgserver/main.go +++ b/cmd/pkgserver/main.go @@ -11,6 +11,7 @@ import ( "time" "hakurei.app/check" + "hakurei.app/cmd/pkgserver/internal/ui" "hakurei.app/command" "hakurei.app/internal/pkg" "hakurei.app/internal/rosa" @@ -81,7 +82,7 @@ func main() { } }() var mux http.ServeMux - uiRoutes(&mux) + ui.Register(&mux) index.registerAPI(&mux) server := http.Server{ Addr: flagAddr, diff --git a/cmd/pkgserver/ui.go b/cmd/pkgserver/ui.go deleted file mode 100644 index 54ab2696..00000000 --- a/cmd/pkgserver/ui.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import "net/http" - -func serveWebUI(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - w.Header().Set("Pragma", "no-cache") - w.Header().Set("Expires", "0") - w.Header().Set("X-Content-Type-Options", "nosniff") - w.Header().Set("X-XSS-Protection", "1") - w.Header().Set("X-Frame-Options", "DENY") - - http.ServeFileFS(w, r, content, "ui/index.html") -} -func serveStaticContent(w http.ResponseWriter, r *http.Request) { - switch r.URL.Path { - case "/static/style.css": - http.ServeFileFS(w, r, content, "ui/static/style.css") - case "/favicon.ico": - http.ServeFileFS(w, r, content, "ui/static/favicon.ico") - case "/static/index.js": - http.ServeFileFS(w, r, content, "ui/static/index.js") - default: - http.NotFound(w, r) - - } -} - -func uiRoutes(mux *http.ServeMux) { - mux.HandleFunc("GET /{$}", serveWebUI) - mux.HandleFunc("GET /favicon.ico", serveStaticContent) - mux.HandleFunc("GET /static/", serveStaticContent) -} diff --git a/cmd/pkgserver/ui/static/favicon.ico b/cmd/pkgserver/ui/static/favicon.ico deleted file mode 100644 index 2fefdfd7efe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)}Y- zAaRg~Ks3mMAoD;phz}D7dGHSd0~3^HbN>&vmjy(F%HE*XU;#1* l#0N?LKfv4wrXPSp<^TWx2heDk_ye%>{{R00l?Q8r5dcr}!IuC4 diff --git a/cmd/pkgserver/ui_full.go b/cmd/pkgserver/ui_full.go deleted file mode 100644 index f7f730c6..00000000 --- a/cmd/pkgserver/ui_full.go +++ /dev/null @@ -1,9 +0,0 @@ -//go:build frontend - -package main - -import "embed" - -//go:generate tsc -p ui -//go:embed ui/* -var content embed.FS