fix: 调整请求体大小限制配置位置与范围

将全局请求体上限配置移除,改为在需要上传的路由分组中单独配置,适配PDF/照片上传需求,避免默认1MB限制导致413错误
This commit is contained in:
SunYF
2026-09-01 08:32:57 +08:00
parent bb1bb2c3f5
commit 31f3d94be1
4 changed files with 17 additions and 2 deletions
+2 -1
View File
@@ -14,7 +14,7 @@ func RegisterRoutes(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes([]rest.Route{
{Method: http.MethodPost, Path: "/login", Handler: LoginHandler(serverCtx)},
{Method: http.MethodPost, Path: "/refresh", Handler: RefreshHandler(serverCtx)},
}, rest.WithPrefix("/api/v1"))
}, rest.WithPrefix("/api/v1"), rest.WithMaxBytes(serverCtx.Config.Upload.MaxMB<<20))
// JWT 保护:用户信息 + 用户/角色/权限 管理
jwtAdmin := []rest.Route{
@@ -41,5 +41,6 @@ func RegisterRoutes(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMiddlewares([]rest.Middleware{permissionGuard(serverCtx)}, jwtAdmin...),
rest.WithPrefix("/api/v1"),
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithMaxBytes(serverCtx.Config.Upload.MaxMB<<20),
)
}
@@ -142,5 +142,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
rest.WithMiddlewares([]rest.Middleware{permissionGuard(serverCtx)}, jwtRoutes...),
rest.WithPrefix("/api/v1"),
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
// 请求体上限跟随 Upload.MaxMB(默认20MB),否则 go-zero 默认 1MB 会 413PDF/照片上传在此分组)
rest.WithMaxBytes(serverCtx.Config.Upload.MaxMB<<20),
)
}