mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 10:55:51 +02:00
fix: websocket proxy invalid
This commit is contained in:
parent
80a66669e0
commit
7cf38254a7
2 changed files with 14 additions and 10 deletions
|
@ -53,17 +53,17 @@ func AuthRequired() gin.HandlerFunc {
|
||||||
c.Set("ProxyNodeID", xNodeID)
|
c.Set("ProxyNodeID", xNodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
token := getToken(c)
|
if token := c.GetHeader("X-Node-Secret"); token != "" && token == settings.NodeSettings.Secret {
|
||||||
if token == "" {
|
|
||||||
if token = c.GetHeader("X-Node-Secret"); token != "" && token == settings.NodeSettings.Secret {
|
|
||||||
c.Set("Secret", token)
|
c.Set("Secret", token)
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
token := getToken(c)
|
||||||
|
if token == "" {
|
||||||
abortWithAuthFailure()
|
abortWithAuthFailure()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
u, ok := user.GetTokenUser(token)
|
u, ok := user.GetTokenUser(token)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/query"
|
"github.com/0xJacky/Nginx-UI/query"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pretty66/websocketproxy"
|
"github.com/pretty66/websocketproxy"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/uozi-tech/cosy/logger"
|
"github.com/uozi-tech/cosy/logger"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProxyWs() gin.HandlerFunc {
|
func ProxyWs() gin.HandlerFunc {
|
||||||
|
@ -26,7 +27,6 @@ func ProxyWs() gin.HandlerFunc {
|
||||||
|
|
||||||
env := query.Environment
|
env := query.Environment
|
||||||
environment, err := env.Where(env.ID.Eq(id)).First()
|
environment, err := env.Where(env.ID.Eq(id)).First()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
return
|
return
|
||||||
|
@ -43,6 +43,10 @@ func ProxyWs() gin.HandlerFunc {
|
||||||
|
|
||||||
wp, err := websocketproxy.NewProxy(decodedUri, func(r *http.Request) error {
|
wp, err := websocketproxy.NewProxy(decodedUri, func(r *http.Request) error {
|
||||||
r.Header.Set("X-Node-Secret", environment.Token)
|
r.Header.Set("X-Node-Secret", environment.Token)
|
||||||
|
r.Header.Del("X-Node-ID")
|
||||||
|
queryValues := r.URL.Query()
|
||||||
|
queryValues.Del("x_node_id")
|
||||||
|
r.URL.RawQuery = queryValues.Encode()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue