From e41ff2b897be24a894e75b850f1c06652cc034be Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 14 May 2022 17:02:30 -0600 Subject: Implement index handler This involved re-arranging how templates are being parsed, slightly. --- srv/src/api/api.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'srv/src/api/api.go') diff --git a/srv/src/api/api.go b/srv/src/api/api.go index 92771a1..79979be 100644 --- a/srv/src/api/api.go +++ b/srv/src/api/api.go @@ -3,10 +3,8 @@ package api import ( "context" - "embed" "errors" "fmt" - "html/template" "net" "net/http" "net/http/httputil" @@ -22,11 +20,6 @@ import ( "github.com/mediocregopher/mediocre-go-lib/v2/mlog" ) -//go:embed tpl -var fs embed.FS - -var tpls = template.Must(template.ParseFS(fs, "tpl/*")) - // Params are used to instantiate a new API instance. All fields are required // unless otherwise noted. type Params struct { @@ -184,10 +177,9 @@ func (a *api) handler() http.Handler { ))) var apiHandler http.Handler = apiMux - apiHandler = postOnlyMiddleware(apiHandler) // TODO probably should be last? apiHandler = checkCSRFMiddleware(apiHandler) - apiHandler = logMiddleware(a.params.Logger, apiHandler) - apiHandler = annotateMiddleware(apiHandler) + apiHandler = postOnlyMiddleware(apiHandler) + apiHandler = logReqMiddleware(apiHandler) apiHandler = addResponseHeaders(map[string]string{ "Cache-Control": "no-store, max-age=0", "Pragma": "no-cache", @@ -196,7 +188,12 @@ func (a *api) handler() http.Handler { mux.Handle("/api/", http.StripPrefix("/api", apiHandler)) - mux.Handle("/v2/posts/", a.postHandler()) + // TODO need to setCSRFMiddleware on all these rendering endpoints + mux.Handle("/v2/posts/", a.renderPostHandler()) + mux.Handle("/v2/", a.renderIndexHandler()) + + var globalHandler http.Handler = mux + globalHandler = setLoggerMiddleware(a.params.Logger, globalHandler) - return mux + return globalHandler } -- cgit v1.2.3