修改1panel兼容v2、接口不存在时返回404

This commit is contained in:
v-me-50
2025-07-09 16:32:28 +08:00
parent 8c89e1ea2a
commit 68df9af02b
2 changed files with 44 additions and 20 deletions

View File

@@ -3,10 +3,12 @@ package route
import (
"ALLinSSL/backend/app/api"
"ALLinSSL/backend/app/api/monitor"
"ALLinSSL/backend/public"
"ALLinSSL/static"
"github.com/gin-gonic/gin"
"io/fs"
"net/http"
"strings"
)
func Register(r *gin.Engine) {
@@ -119,6 +121,11 @@ func Register(r *gin.Engine) {
// 其他路由:返回 index.html
r.NoRoute(func(c *gin.Context) {
// 如果是 API 请求,返回 JSON 的 404
if strings.HasPrefix(c.Request.URL.Path, "/v1/") {
public.FailMsg(c, "请求的资源不存在")
return
}
data, err := static.BuildFS.ReadFile("build/index.html")
if err != nil {
c.String(http.StatusInternalServerError, "页面加载失败")