Fixed static content path and made content caching optional.

This commit is contained in:
Marvin Blum
2019-12-27 20:07:25 +01:00
parent 9f5197ba3e
commit ef1223b4aa
5 changed files with 13 additions and 3 deletions

11
main.go
View File

@@ -14,7 +14,7 @@ import (
) )
const ( const (
staticDir = "public/static" staticDir = "static"
staticDirPrefix = "/static/" staticDirPrefix = "/static/"
envPrefix = "SCHNITTFEST_" envPrefix = "SCHNITTFEST_"
pwdString = "PASSWORD" // do not log passwords! pwdString = "PASSWORD" // do not log passwords!
@@ -23,6 +23,10 @@ const (
defaultHttpReadTimeout = 20 defaultHttpReadTimeout = 20
) )
var (
disableCache = strings.ToLower(os.Getenv("SCHNITTFEST_DISABLE_CACHE")) == "true"
)
func configureLog() { func configureLog() {
logbuch.Info("Configure logging...") logbuch.Info("Configure logging...")
logbuch.SetFormatter(logbuch.NewFieldFormatter("", "\t")) logbuch.SetFormatter(logbuch.NewFieldFormatter("", "\t"))
@@ -52,7 +56,10 @@ func setupRouter() *mux.Router {
// static content // static content
fs := http.StripPrefix(staticDirPrefix, http.FileServer(http.Dir(staticDir))) fs := http.StripPrefix(staticDirPrefix, http.FileServer(http.Dir(staticDir)))
router.PathPrefix(staticDirPrefix).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 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) fs.ServeHTTP(w, r)
}).Methods("GET") }).Methods("GET")

View File

@@ -2,5 +2,6 @@ set SCHNITTFEST_HOST=localhost:8080
set SCHNITTFEST_LOGLEVEL=debug set SCHNITTFEST_LOGLEVEL=debug
set SCHNITTFEST_ALLOWED_ORIGINS=* set SCHNITTFEST_ALLOWED_ORIGINS=*
set SCHNITTFEST_TLS_ENABLE=false set SCHNITTFEST_TLS_ENABLE=false
set SCHNITTFEST_DISABLE_CACHE=true
go run main.go go run main.go

View File

@@ -4,5 +4,6 @@ export SCHNITTFEST_HOST=localhost:8080
export SCHNITTFEST_LOGLEVEL=debug export SCHNITTFEST_LOGLEVEL=debug
export SCHNITTFEST_ALLOWED_ORIGINS=* export SCHNITTFEST_ALLOWED_ORIGINS=*
export SCHNITTFEST_TLS_ENABLE=false export SCHNITTFEST_TLS_ENABLE=false
export SCHNITTFEST_DISABLE_CACHE=true
go run main.go go run main.go

View File

@@ -1 +1 @@
html,body{font-family:sans-serif} html,body{font-family:sans-serif;font-size:40px}

View File

@@ -1,3 +1,4 @@
html, body { html, body {
font-family: sans-serif; font-family: sans-serif;
font-size: 40px;
} }