mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +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,16 +53,16 @@ func AuthRequired() gin.HandlerFunc {
|
|||
c.Set("ProxyNodeID", xNodeID)
|
||||
}
|
||||
|
||||
if token := c.GetHeader("X-Node-Secret"); token != "" && token == settings.NodeSettings.Secret {
|
||||
c.Set("Secret", token)
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
token := getToken(c)
|
||||
if token == "" {
|
||||
if token = c.GetHeader("X-Node-Secret"); token != "" && token == settings.NodeSettings.Secret {
|
||||
c.Set("Secret", token)
|
||||
c.Next()
|
||||
return
|
||||
} else {
|
||||
abortWithAuthFailure()
|
||||
return
|
||||
}
|
||||
abortWithAuthFailure()
|
||||
return
|
||||
}
|
||||
|
||||
u, ok := user.GetTokenUser(token)
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pretty66/websocketproxy"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ProxyWs() gin.HandlerFunc {
|
||||
|
@ -26,7 +27,6 @@ func ProxyWs() gin.HandlerFunc {
|
|||
|
||||
env := query.Environment
|
||||
environment, err := env.Where(env.ID.Eq(id)).First()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
|
@ -43,6 +43,10 @@ func ProxyWs() gin.HandlerFunc {
|
|||
|
||||
wp, err := websocketproxy.NewProxy(decodedUri, func(r *http.Request) error {
|
||||
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
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue