cmd/pkgserver: flatten static site
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="static/style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<title>Hakurei PkgServer</title>
|
<title>Hakurei PkgServer</title>
|
||||||
<script src="static/index.js"></script>
|
<script src="index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hakurei PkgServer</h1>
|
<h1>Hakurei PkgServer</h1>
|
||||||
|
|||||||
@@ -3,19 +3,7 @@ package ui
|
|||||||
|
|
||||||
import "net/http"
|
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.
|
// Register arranges for mux to serve the embedded frontend.
|
||||||
func Register(mux *http.ServeMux) {
|
func Register(mux *http.ServeMux) {
|
||||||
mux.Handle("GET /", http.FileServer(http.FS(content)))
|
mux.Handle("GET /", http.FileServer(http.FS(static)))
|
||||||
mux.HandleFunc("GET /{$}", serveWebUI)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,20 @@
|
|||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import "embed"
|
import (
|
||||||
|
"embed"
|
||||||
|
"io/fs"
|
||||||
|
)
|
||||||
|
|
||||||
//go:generate tsc
|
//go:generate tsc
|
||||||
//go:generate cp index.html style.css static
|
//go:generate cp index.html style.css static
|
||||||
//go:embed static
|
//go:embed static
|
||||||
var content embed.FS
|
var _static embed.FS
|
||||||
|
|
||||||
|
var static = func() fs.FS {
|
||||||
|
if f, err := fs.Sub(_static, "static"); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else {
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ package ui
|
|||||||
|
|
||||||
import "testing/fstest"
|
import "testing/fstest"
|
||||||
|
|
||||||
var content fstest.MapFS
|
var static fstest.MapFS
|
||||||
|
|||||||
Reference in New Issue
Block a user