set 'Tk: N' header on resources loaded by client. #65

This commit is contained in:
Danny 2018-06-13 11:15:18 +02:00
parent 42cd00b8cd
commit 844c5996ff
2 changed files with 15 additions and 2 deletions

View File

@ -122,11 +122,16 @@ func (api *API) NewCollectHandler() http.Handler {
return err
}
// don't you cache this
// indicate that we're not tracking user data, see https://github.com/usefathom/fathom/issues/65
w.Header().Set("Tk", "N")
// headers to prevent caching
w.Header().Set("Content-Type", "image/gif")
w.Header().Set("Expires", "Mon, 01 Jan 1990 00:00:00 GMT")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
// response
w.WriteHeader(http.StatusOK)
// 1x1 px transparent GIF

View File

@ -29,10 +29,18 @@ func (api *API) Routes() *mux.Router {
// static assets & 404 handler
box := packr.NewBox("./../../assets/build")
r.Path("/tracker.js").Handler(serveFileHandler(&box, "js/tracker.js"))
r.Path("/tracker.js").Handler(serveTrackerFile(&box))
r.Path("/").Handler(serveFileHandler(&box, "index.html"))
r.PathPrefix("/assets").Handler(http.StripPrefix("/assets", http.FileServer(box)))
r.NotFoundHandler = NotFoundHandler(&box)
return r
}
func serveTrackerFile(box *packr.Box) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Tk", "N")
next := serveFile(box, "js/tracker.js")
next.ServeHTTP(w, r)
})
}