diff --git a/pkg/routes/index.go b/pkg/routes/index.go index c3f654b..c002abc 100644 --- a/pkg/routes/index.go +++ b/pkg/routes/index.go @@ -1,23 +1,30 @@ package routes import ( - "net/http" + "bytes" routing "github.com/jackwhelpton/fasthttp-routing/v2" + "github.com/valyala/fasthttp" "code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/content" "code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/params" "code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates" ) -// rootRedirect redirects the root url to the index using http redirect -func (r *Routes) rootRedirect(c *routing.Context) (err error) { +// relativeRedirectBytes makes a relative redirect by using http Location header +func (r *Routes) relativeRedirectBytes(c *routing.Context, location []byte, statusCode int) (err error) { - c.Redirect(templates.URLIndex, http.StatusFound) + c.Response.Header.SetCanonical([]byte(fasthttp.HeaderLocation), location) + c.Response.SetStatusCode(statusCode) return } +// rootRedirect redirects the root url to the index using http redirect +func (r *Routes) rootRedirect(c *routing.Context) (err error) { + return r.relativeRedirectBytes(c, []byte(templates.URLIndex), fasthttp.StatusFound) +} + // index handler renders index data func (r *Routes) index(c *routing.Context) (err error) { diff --git a/pkg/templates/urls.go b/pkg/templates/urls.go index 29e7f56..d2c931d 100644 --- a/pkg/templates/urls.go +++ b/pkg/templates/urls.go @@ -1,9 +1,11 @@ package templates const ( + URLPostfix = "aspx" + URLRoot = "/" - URLIndex = "/index.aspx" - URLBlog = "/blog.aspx" - URLPost = "/post.aspx" + URLIndex = "/index." + URLPostfix + URLBlog = "/blog." + URLPostfix + URLPost = "/post." + URLPostfix URLJSApp = "/js-bin/app.js" )