diff options
Diffstat (limited to 'cmd/server/handlers.go')
| -rw-r--r-- | cmd/server/handlers.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go index cb63774..869e5ba 100644 --- a/cmd/server/handlers.go +++ b/cmd/server/handlers.go @@ -7,14 +7,23 @@ import ( "github.com/gorilla/mux" "riedstra.dev/mitch/go-website/page" + "riedstra.dev/mitch/go-website/rediscache" ) func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) { rtr := mux.NewRouter() rtr.HandleFunc(a.ReIndexPath, a.RebuildIndexHandler) rtr.PathPrefix("/static/").Handler(a.StaticHandler()) - rtr.PathPrefix(fmt.Sprintf("/%s/{tag}", a.FeedPrefix)).HandlerFunc(a.FeedHandler) - rtr.PathPrefix("/").HandlerFunc(a.PageHandler) + rtr.PathPrefix(fmt.Sprintf("/%s/{tag}", a.FeedPrefix)).HandlerFunc( + a.FeedHandler) + + if a.redisPool != nil { + rtr.PathPrefix("/").Handler(rediscache.Handle( + a.redisPool, http.HandlerFunc(a.PageHandler))) + } else { + rtr.PathPrefix("/").Handler(http.HandlerFunc(a.PageHandler)) + } + rtr.ServeHTTP(w, r) } @@ -23,6 +32,7 @@ func (a *App) PageHandler(w http.ResponseWriter, r *http.Request) { if u == "/" { u = "/index" } + u = filepath.Join(".", u) page.RenderForPath(w, r, u) @@ -33,6 +43,7 @@ func (a *App) RebuildIndexHandler(w http.ResponseWriter, r *http.Request) { if u == "/" { u = "/index" } + u = filepath.Join(".", u) p := page.NewPage("index") @@ -44,7 +55,7 @@ func (a *App) RebuildIndexHandler(w http.ResponseWriter, r *http.Request) { } // StaticHandler simply returns a HTTP handler that looks at the current -// directory and exposes `static` via HTTP `/static` +// directory and exposes `static` via HTTP `/static`. func (a *App) StaticHandler() http.Handler { return http.StripPrefix("/static/", http.FileServer(http.Dir(a.StaticDirectory))) } |
