refactor: introduce trString for frontend (#38741)

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
wxiaoguang
2026-08-03 12:40:02 +08:00
committed by GitHub
parent cb4c65f035
commit c2ebe3724f
12 changed files with 51 additions and 21 deletions
+3 -3
View File
@@ -89,7 +89,7 @@ func getViteDevProxy() *httputil.ReverseProxy {
func ViteDevMiddleware(next http.Handler) http.Handler {
markLongPolling := routing.MarkLongPolling()
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if !isViteDevRequest(req) {
if !IsViteDevRequest(req) {
next.ServeHTTP(resp, req)
return
}
@@ -149,9 +149,9 @@ func viteDevSourceURL(srcPath string) string {
return setting.AppSubURL + "/" + srcPath
}
// isViteDevRequest returns true if the request should be proxied to the Vite dev server.
// IsViteDevRequest returns true if the request should be proxied to the Vite dev server.
// Ref: Vite source packages/vite/src/node/constants.ts and packages/vite/src/shared/constants.ts
func isViteDevRequest(req *http.Request) bool {
func IsViteDevRequest(req *http.Request) bool {
if req.Header.Get("Upgrade") == "websocket" {
wsProtocol := req.Header.Get("Sec-WebSocket-Protocol")
return wsProtocol == "vite-hmr" || wsProtocol == "vite-ping"
+2 -1
View File
@@ -10,6 +10,7 @@ import (
"strings"
"gitea.dev/modules/htmlutil"
"gitea.dev/modules/public"
"gitea.dev/modules/reqctx"
"gitea.dev/modules/setting"
"gitea.dev/modules/web/middleware"
@@ -256,7 +257,7 @@ func (r *Router) normalizeRequestPath(resp http.ResponseWriter, req *http.Reques
normalizedPath = "/" + remainingPath
} else if normalizedPath == setting.AppSubURL {
normalizedPath = "/"
} else if !strings.HasPrefix(normalizedPath+"/", "/v2/") {
} else if !strings.HasPrefix(normalizedPath+"/", "/v2/") && !public.IsViteDevRequest(req) {
// do not respond to other requests, to simulate a real sub-path environment
resp.Header().Add("Content-Type", "text/html; charset=utf-8")
resp.WriteHeader(http.StatusNotFound)