Skip to content

Commit

Permalink
fix: return 404 when page not found (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanljh authored Dec 30, 2024
1 parent 1802093 commit cea4031
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/dashboard/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,26 +303,32 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
}
return func(c *gin.Context) {
if strings.HasPrefix(c.Request.URL.Path, "/api") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
c.JSON(http.StatusNotFound, newErrorResponse(errors.New("404 Not Found")))
return
}
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
localFilePath := path.Join(singleton.Conf.AdminTemplate, stripPath)
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return
} else {
c.Status(http.StatusNotFound)
c.Writer.WriteHeaderNow();
}
if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.AdminTemplate+"/index.html") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
c.JSON(http.StatusNotFound, newErrorResponse(errors.New("404 Not Found")))
}
return
}
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return
} else {
c.Status(http.StatusNotFound)
c.Writer.WriteHeaderNow();
}
if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.UserTemplate+"/index.html") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
c.JSON(http.StatusNotFound, newErrorResponse(errors.New("404 Not Found")))
}
}
}

0 comments on commit cea4031

Please sign in to comment.