diff --git a/pkg/routes/index.go b/pkg/routes/index.go index c002abc..ffeabea 100644 --- a/pkg/routes/index.go +++ b/pkg/routes/index.go @@ -25,6 +25,25 @@ func (r *Routes) rootRedirect(c *routing.Context) (err error) { return r.relativeRedirectBytes(c, []byte(templates.URLIndex), fasthttp.StatusFound) } +// rootRedirect forcefully adds postfix to the url +func (r *Routes) usePostfixForce(c *routing.Context) (err error) { + + fullPath := c.Path() + if len(fullPath) <= 1 { + return c.Next() + } + + dotIndex := bytes.LastIndexByte(fullPath, '.') + if dotIndex >= 0 { + return c.Next() + } + + fullPath = append(fullPath, '.') + fullPath = append(fullPath, []byte(templates.URLPostfix)...) + + return r.relativeRedirectBytes(c, fullPath, fasthttp.StatusFound) +} + // index handler renders index data func (r *Routes) index(c *routing.Context) (err error) { diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index f2a8a3b..2be16a0 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -37,6 +37,7 @@ func (r *Routes) init() { router.Use(r.useTemplateWriter) router.Use(r.useErrorHandler) + router.Use(r.usePostfixForce) router.NotFound(r.errorNotFound) root := router.Group(r.Base)