🎨 Improve kernel HTTP panic recover Fix https://github.com/siyuan-note/siyuan/issues/7888
This commit is contained in:
parent
0d832cc97e
commit
813de05019
2 changed files with 30 additions and 3 deletions
|
@ -19,6 +19,7 @@ package model
|
|||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -230,3 +231,26 @@ func CheckAuth(c *gin.Context) {
|
|||
|
||||
c.Next()
|
||||
}
|
||||
|
||||
var timingAPIs = map[string]bool{
|
||||
"/api/search": true,
|
||||
}
|
||||
|
||||
func Timing(c *gin.Context) {
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
c.Next()
|
||||
elapsed := time.Now().UnixMilli() - now
|
||||
//if 000 < elapsed {
|
||||
logging.LogInfof("[%s] elapsed [%dms]", c.Request.RequestURI, elapsed)
|
||||
//}
|
||||
}
|
||||
|
||||
func Recover(c *gin.Context) {
|
||||
defer func() {
|
||||
logging.Recover()
|
||||
c.Status(500)
|
||||
}()
|
||||
|
||||
c.Next()
|
||||
}
|
||||
|
|
|
@ -51,9 +51,12 @@ func Serve(fastMode bool) {
|
|||
gin.SetMode(gin.ReleaseMode)
|
||||
ginServer := gin.New()
|
||||
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
||||
ginServer.Use(gin.Recovery())
|
||||
ginServer.Use(corsMiddleware()) // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
||||
ginServer.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp3", ".wav", ".ogg", ".mov", ".weba", ".mkv", ".mp4", ".webm"})))
|
||||
ginServer.Use(
|
||||
model.Timing,
|
||||
model.Recover,
|
||||
corsMiddleware(), // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
||||
gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp3", ".wav", ".ogg", ".mov", ".weba", ".mkv", ".mp4", ".webm"})),
|
||||
)
|
||||
|
||||
cookieStore.Options(sessions.Options{
|
||||
Path: "/",
|
||||
|
|
Loading…
Add table
Reference in a new issue