mirror of
https://github.com/Kugelschieber/schnittfest.git
synced 2026-01-18 10:20:27 +00:00
Fixed static content path and made content caching optional.
This commit is contained in:
11
main.go
11
main.go
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
staticDir = "public/static"
|
||||
staticDir = "static"
|
||||
staticDirPrefix = "/static/"
|
||||
envPrefix = "SCHNITTFEST_"
|
||||
pwdString = "PASSWORD" // do not log passwords!
|
||||
@@ -23,6 +23,10 @@ const (
|
||||
defaultHttpReadTimeout = 20
|
||||
)
|
||||
|
||||
var (
|
||||
disableCache = strings.ToLower(os.Getenv("SCHNITTFEST_DISABLE_CACHE")) == "true"
|
||||
)
|
||||
|
||||
func configureLog() {
|
||||
logbuch.Info("Configure logging...")
|
||||
logbuch.SetFormatter(logbuch.NewFieldFormatter("", "\t"))
|
||||
@@ -52,7 +56,10 @@ func setupRouter() *mux.Router {
|
||||
// static content
|
||||
fs := http.StripPrefix(staticDirPrefix, http.FileServer(http.Dir(staticDir)))
|
||||
router.PathPrefix(staticDirPrefix).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Cache-Control", "max-age=3600")
|
||||
if !disableCache {
|
||||
w.Header().Add("Cache-Control", "max-age=3600")
|
||||
}
|
||||
|
||||
fs.ServeHTTP(w, r)
|
||||
}).Methods("GET")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user