diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2023-01-21 16:46:11 +0100 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2023-01-21 16:46:11 +0100 |
commit | 293655452cfc6a106c55384e839f9c07d340b954 (patch) | |
tree | c01202bb1722f6f6a0f500f304fa2fbf3c35c34b /src/gmi/gmi.go | |
parent | 7878db5c95e5eb430b7b878fe6eb8084f15441a7 (diff) |
Continue to polish up posts pages
Diffstat (limited to 'src/gmi/gmi.go')
-rw-r--r-- | src/gmi/gmi.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/gmi/gmi.go b/src/gmi/gmi.go index 7d4d186..b543e05 100644 --- a/src/gmi/gmi.go +++ b/src/gmi/gmi.go @@ -119,6 +119,21 @@ func (a *api) Shutdown(ctx context.Context) error { return a.srv.Shutdown(ctx) } +func indexMiddleware(h gemini.Handler) gemini.Handler { + + return gemini.HandlerFunc(func( + ctx context.Context, + rw gemini.ResponseWriter, + r *gemini.Request, + ) { + if strings.HasSuffix(r.URL.Path, "/") { + r.URL.Path += "index.gmi" + } + + h.ServeGemini(ctx, rw, r) + }) +} + func postsMiddleware(tplHandler gemini.Handler) gemini.Handler { return gemini.HandlerFunc(func( @@ -156,7 +171,10 @@ func (a *api) handler() (gemini.Handler, error) { mux.Handle("/posts/", postsMiddleware(tplHandler)) mux.Handle("/", tplHandler) - h := mux + var h gemini.Handler + + h = mux + h = indexMiddleware(h) // TODO logging // TODO caching |