socket fix
This commit is contained in:
parent
bd67125ee4
commit
a3c7bbed44
@ -60,6 +60,14 @@
|
||||
"allow_untrusted": false
|
||||
}
|
||||
],
|
||||
"/socket.io": [
|
||||
{
|
||||
"url": "https://yobble-socket-service",
|
||||
"role": "master",
|
||||
"yobble_signed": true,
|
||||
"allow_untrusted": false
|
||||
}
|
||||
],
|
||||
"/test": [
|
||||
{
|
||||
"url": "https://localhost:9097",
|
||||
|
||||
@ -62,6 +62,15 @@ func RemoveTrailingSlashMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
urlPath := r.URL.Path
|
||||
|
||||
// Skip redirect for Socket.IO and WebSocket upgrade traffic
|
||||
// Socket.IO may rely on a trailing slash in polling endpoints.
|
||||
if strings.HasPrefix(urlPath, "/socket.io") || strings.HasPrefix(urlPath, "/ws/socket.io") ||
|
||||
strings.EqualFold(r.Header.Get("Upgrade"), "websocket") ||
|
||||
strings.Contains(strings.ToLower(r.Header.Get("Connection")), "upgrade") {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if urlPath != "" && urlPath != "/" && strings.HasSuffix(urlPath, "/") {
|
||||
newPath := strings.TrimSuffix(urlPath, "/")
|
||||
newURL := *r.URL
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"yobble-gateway-go/internal/config"
|
||||
"yobble-gateway-go/internal/logger"
|
||||
@ -58,7 +59,11 @@ func NewProxyHandler(cfg *config.Settings, geoIPService *geoip.GeoIPService) htt
|
||||
originalDirector(req) // Устанавливает базовые заголовки и URL
|
||||
|
||||
// Устанавливаем правильный путь для бэкенда
|
||||
if strings.HasPrefix(r.URL.Path, "/socket.io") {
|
||||
req.URL.Path = r.URL.Path
|
||||
} else {
|
||||
req.URL.Path = tailPath
|
||||
}
|
||||
|
||||
// Устанавливаем заголовки для информирования бэкенда об исходном запросе
|
||||
req.Header.Set("X-Real-IP", realIP)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user