Always redirect to a postfixed path

This commit is contained in:
2022-01-26 04:25:20 +01:00
parent 8f3e81fac3
commit 1e6cbd574f
2 changed files with 20 additions and 0 deletions
+19
View File
@@ -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) {
+1
View File
@@ -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)