mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Always redirect to a postfixed path
This commit is contained in:
@@ -25,6 +25,25 @@ func (r *Routes) rootRedirect(c *routing.Context) (err error) {
|
|||||||
return r.relativeRedirectBytes(c, []byte(templates.URLIndex), fasthttp.StatusFound)
|
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
|
// index handler renders index data
|
||||||
func (r *Routes) index(c *routing.Context) (err error) {
|
func (r *Routes) index(c *routing.Context) (err error) {
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func (r *Routes) init() {
|
|||||||
|
|
||||||
router.Use(r.useTemplateWriter)
|
router.Use(r.useTemplateWriter)
|
||||||
router.Use(r.useErrorHandler)
|
router.Use(r.useErrorHandler)
|
||||||
|
router.Use(r.usePostfixForce)
|
||||||
router.NotFound(r.errorNotFound)
|
router.NotFound(r.errorNotFound)
|
||||||
|
|
||||||
root := router.Group(r.Base)
|
root := router.Group(r.Base)
|
||||||
|
|||||||
Reference in New Issue
Block a user