fix for #70 to prevent caching build images

This commit is contained in:
Brad Rydzewski 2014-02-14 13:24:12 -07:00
parent 3e89767952
commit 26c9fb0cc3

View file

@ -73,7 +73,18 @@ func setupDatabase() {
func setupStatic() {
box := rice.MustFindBox("assets")
http.Handle("/css/", http.FileServer(box.HTTPBox()))
http.Handle("/img/", http.FileServer(box.HTTPBox()))
// we need to intercept all attempts to serve images
// so that we can add a cache-control settings
var images = http.FileServer(box.HTTPBox())
http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/img/build_") {
w.Header().Add("Cache-Control", "no-cache")
}
// serce images
images.ServeHTTP(w, r)
})
}
// setup routes for serving dynamic content.
@ -164,8 +175,6 @@ func setupHandlers() {
// the first time a page is requested we should record
// the scheme and hostname.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// get the hostname and scheme
// our multiplexer is a bit finnicky and therefore requires
// us to strip any trailing slashes in order to correctly
// find and match a route.