fix: never return frontend on routes starting with /api

This fixes a problem where Vikunja would sometimes return the html for the frontend when accessing an api route for a nonexistent ressource, because the static handler was the next best.

Resolves vikunja/vikunja#2110
This commit is contained in:
kolaente 2024-02-13 10:05:15 +01:00
parent 18374c2e52
commit 641fec1215
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 3 additions and 0 deletions

View File

@ -141,6 +141,9 @@ func static() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
p := c.Request().URL.Path
if strings.HasPrefix(p, "/api/") {
return next(c)
}
if strings.HasSuffix(c.Path(), "*") { // When serving from a group, e.g. `/static*`.
p = c.Param("*")
}