mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-25 16:00:56 +00:00
feat: core 增加 xpack 节点管理
This commit is contained in:
+28
-12
@@ -1,6 +1,11 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -8,20 +13,31 @@ import (
|
||||
|
||||
func Proxy() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api/v1/auth") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/v1/setting") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/v1/log") {
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api/v2/core") {
|
||||
c.Next()
|
||||
return
|
||||
} else {
|
||||
sockPath := "/tmp/agent.sock"
|
||||
if _, err := os.Stat(sockPath); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dialUnix := func() (conn net.Conn, err error) {
|
||||
return net.Dial("unix", sockPath)
|
||||
}
|
||||
transport := &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return dialUnix()
|
||||
},
|
||||
}
|
||||
proxy := &httputil.ReverseProxy{
|
||||
Director: func(req *http.Request) {
|
||||
req.URL.Scheme = "http"
|
||||
req.URL.Host = "unix"
|
||||
},
|
||||
Transport: transport,
|
||||
}
|
||||
proxy.ServeHTTP(c.Writer, c.Request)
|
||||
c.Abort()
|
||||
}
|
||||
//target, err := url.Parse("http://127.0.0.1:9998")
|
||||
//if err != nil {
|
||||
// fmt.Printf("Failed to parse target URL: %v", err)
|
||||
//}
|
||||
//proxy := httputil.NewSingleHostReverseProxy(target)
|
||||
//c.Request.Host = target.Host
|
||||
//c.Request.URL.Scheme = target.Scheme
|
||||
//c.Request.URL.Host = target.Host
|
||||
//proxy.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user