Skip to content

Commit 481a1a9

Browse files
committed
Caching headers
1 parent 2f88e5e commit 481a1a9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/server/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,28 @@ func RunServer(config *ServerConfig) error {
6666
// Manifest endpoint
6767
r.HandleFunc("/.client/manifest.json", manifestHandler(config))
6868

69-
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
69+
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
7070
path := chi.URLParam(r, "*")
7171

7272
spaceConfig := spaceConfigFromContext(r.Context())
7373

7474
// See if it's in the client bundle
7575
data, meta, err := config.ClientBundle.ReadFile(path)
7676
if err == nil {
77+
// File is in the bundle, let's serve it
78+
if r.Header.Get("If-Modified-Since") == utcDateString(meta.LastModified) {
79+
w.WriteHeader(304)
80+
log.Printf("Sending 304 not modified: %s", path)
81+
return
82+
}
7783
w.Header().Set("Content-Type", meta.ContentType)
84+
w.Header().Set("Last-Modified", utcDateString(meta.LastModified))
7885
w.WriteHeader(200)
7986
w.Write(data)
8087
return
8188
}
8289

90+
// TODO: handle request types
8391
ServerSideRender(config, spaceConfig, path, w, r)
8492
})
8593

0 commit comments

Comments
 (0)