In production mode, embed static content

This commit is contained in:
nemunaire 2019-09-02 15:41:37 +02:00
commit 3dd22ecb09
4 changed files with 80 additions and 5 deletions

View file

@ -8,6 +8,8 @@ import (
"path/filepath"
)
var mux = http.NewServeMux()
var PublishedImgDir string
var NextImgDir string
var ThumbsDir string
@ -61,12 +63,9 @@ func main() {
}
}
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(staticDir, "index.html"))
serveStaticAsset(w, r, "index.html")
})
mux.Handle("/css/", http.FileServer(http.Dir(staticDir)))
mux.Handle("/js/", http.FileServer(http.Dir(staticDir)))
mux.Handle("/api/", http.StripPrefix("/api", ApiHandler(authFunc)))
@ -101,7 +100,7 @@ func main() {
w.Header().Set("WWW-Authenticate", "Basic realm=\"YouP0m\"")
http.Error(w, "You are not allowed to perform this request.", http.StatusUnauthorized)
} else {
http.ServeFile(w, r, filepath.Join(staticDir, "admin.html"))
serveStaticAsset(w, r, "admin.html")
}
})