mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 03:50:16 +08:00
🎨 Improve kernel HTTP panic recover Fix https://github.com/siyuan-note/siyuan/issues/7888
This commit is contained in:
parent
0d832cc97e
commit
813de05019
@ -19,6 +19,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -230,3 +231,26 @@ func CheckAuth(c *gin.Context) {
|
|||||||
|
|
||||||
c.Next()
|
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)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
ginServer := gin.New()
|
ginServer := gin.New()
|
||||||
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 插入较大的资源文件时内存占用较大 https://github.com/siyuan-note/siyuan/issues/5023
|
||||||
ginServer.Use(gin.Recovery())
|
ginServer.Use(
|
||||||
ginServer.Use(corsMiddleware()) // 后端服务支持 CORS 预检请求验证 https://github.com/siyuan-note/siyuan/pull/5593
|
model.Timing,
|
||||||
ginServer.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp3", ".wav", ".ogg", ".mov", ".weba", ".mkv", ".mp4", ".webm"})))
|
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{
|
cookieStore.Options(sessions.Options{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Loading…
Reference in New Issue
Block a user