mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 21:19:19 +00:00
fix serving static files with -base
I deleted the commented-out block because it hasn't been touched in half a year now.
This commit is contained in:
parent
db30fa3c5e
commit
ff39f90abd
@ -14,9 +14,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: gzip?
|
|
||||||
var StaticHandler = http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP
|
|
||||||
|
|
||||||
var routes []Route = []Route{
|
var routes []Route = []Route{
|
||||||
p("/", IndexHandler).ManualAuth(),
|
p("/", IndexHandler).ManualAuth(),
|
||||||
p("/static/*path", StaticHandler).ManualAuth(),
|
p("/static/*path", StaticHandler).ManualAuth(),
|
||||||
@ -78,33 +75,10 @@ func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
|||||||
assets.Render("index.html", rw, nil)
|
assets.Render("index.html", rw, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func StaticHandler(rw http.ResponseWriter, req *http.Request) {
|
func StaticHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP(rw, req)
|
// TODO: gzip?
|
||||||
ctype := mime.TypeByExtension(filepath.Ext(path))
|
http.StripPrefix(BasePath+"/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP(rw, req)
|
||||||
|
|
||||||
if assets != nil {
|
|
||||||
if asset, ok := assets[path]; ok {
|
|
||||||
if req.Header.Get("if-none-match") == asset.etag {
|
|
||||||
rw.WriteHeader(http.StatusNotModified)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rw.Header().Set("Content-Type", ctype)
|
|
||||||
rw.Header().Set("Content-Encoding", "gzip")
|
|
||||||
rw.Header().Set("Etag", asset.etag)
|
|
||||||
rw.Write(*asset.gzip())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open("assets/" + path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
rw.Header().Set("Content-Type", ctype)
|
|
||||||
io.Copy(rw, f)
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func StatusHandler(rw http.ResponseWriter, req *http.Request) {
|
func StatusHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
writeJSON(rw, map[string]interface{}{
|
writeJSON(rw, map[string]interface{}{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user