package web // The mail page's one script and one stylesheet (novox/hq ADR 0515 ยง6, issue 1859), built into the binary and // served from the page's own origin at /static/app.js and /static/app.css, with their types and nosniff; // nothing else is served from /static/. Neither carries anything of a mail. import ( "embed" "net/http" ) //go:embed static/app.js static/app.css var staticFiles embed.FS // staticTypes are the two files and their types. var staticTypes = map[string]string{ "/static/app.js": "text/javascript; charset=utf-8", "/static/app.css": "text/css; charset=utf-8", } // staticPage answers /static/app.js and /static/app.css; anything else under /static/ is 404. func staticPage(w http.ResponseWriter, r *http.Request) { typ, ok := staticTypes[r.URL.Path] if !ok || (r.Method != http.MethodGet && r.Method != http.MethodHead) { http.NotFound(w, r) return } body, err := staticFiles.ReadFile(r.URL.Path[1:]) if err != nil { http.NotFound(w, r) return } w.Header().Set("Content-Type", typ) w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("Cache-Control", "no-cache") _, _ = w.Write(body) }