cmd/pkgserver: move ui internal

This avoids inadvertently exporting a go package. This change also cleans up generate layout.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-02 03:15:07 +09:00
parent 1c277d30a6
commit 5e50fede9a
12 changed files with 35 additions and 45 deletions

2
.gitignore vendored
View File

@@ -7,7 +7,7 @@
# go generate # go generate
/cmd/hakurei/LICENSE /cmd/hakurei/LICENSE
/cmd/pkgserver/ui/static/*.js /cmd/pkgserver/internal/ui/static
/internal/pkg/testdata/testtool /internal/pkg/testdata/testtool
/internal/rosa/hakurei_current.tar.gz /internal/rosa/hakurei_current.tar.gz

View File

@@ -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)
}

View File

@@ -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

View File

@@ -1,6 +1,6 @@
//go:build !frontend //go:build !frontend
package main package ui
import "testing/fstest" import "testing/fstest"

View File

@@ -11,6 +11,7 @@ import (
"time" "time"
"hakurei.app/check" "hakurei.app/check"
"hakurei.app/cmd/pkgserver/internal/ui"
"hakurei.app/command" "hakurei.app/command"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
"hakurei.app/internal/rosa" "hakurei.app/internal/rosa"
@@ -81,7 +82,7 @@ func main() {
} }
}() }()
var mux http.ServeMux var mux http.ServeMux
uiRoutes(&mux) ui.Register(&mux)
index.registerAPI(&mux) index.registerAPI(&mux)
server := http.Server{ server := http.Server{
Addr: flagAddr, Addr: flagAddr,

View File

@@ -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)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -1,9 +0,0 @@
//go:build frontend
package main
import "embed"
//go:generate tsc -p ui
//go:embed ui/*
var content embed.FS