Update Mihomo configuration and documentation for clarity
- Revised comments in `config.example.yaml` to enhance understanding of Mihomo integration, including environment variable usage and Docker Compose setup. - Updated `docker-compose.yml` comments to clarify the relationship between the gateway and Mihomo service. - Enhanced `GATEWAY_RUN.md` to provide clearer instructions on configuring Mihomo parameters and their usage in the gateway.
This commit is contained in:
+19
-15
@@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
// NewMihomoForward proxies /api/{alias}/mihomo/... to Mihomo external-controller (REST + WebSocket).
|
||||
// Используется Rewrite (Go 1.20+): очищается RequestURI и задаётся абсолютный URL — иначе строгий upstream
|
||||
// и WebSocket upgrade могут отвечать 400 (см. аналогично Telemt в forward.go).
|
||||
func NewMihomoForward(
|
||||
target *url.URL,
|
||||
stripPrefix string,
|
||||
@@ -23,27 +25,30 @@ func NewMihomoForward(
|
||||
rt = http.DefaultTransport
|
||||
}
|
||||
rp := &httputil.ReverseProxy{
|
||||
Director: func(req *http.Request) {
|
||||
NormalizeRequestURLPath(req)
|
||||
p := req.URL.Path
|
||||
Rewrite: func(pr *httputil.ProxyRequest) {
|
||||
NormalizeRequestURLPath(pr.In)
|
||||
p := pr.In.URL.Path
|
||||
if !strings.HasPrefix(p, stripPrefix) {
|
||||
return
|
||||
}
|
||||
rest := strings.TrimPrefix(p, stripPrefix)
|
||||
rest = strings.TrimPrefix(rest, "/")
|
||||
q := req.URL.RawQuery
|
||||
rest := strings.TrimPrefix(strings.TrimPrefix(p, stripPrefix), "/")
|
||||
dest := JoinPathPrefix(target, "/", rest)
|
||||
req.URL.Scheme = dest.Scheme
|
||||
req.URL.Host = dest.Host
|
||||
req.URL.Path = dest.Path
|
||||
req.URL.RawQuery = q
|
||||
req.Host = dest.Host
|
||||
req.Header.Del("Authorization")
|
||||
du := *dest
|
||||
du.RawQuery = pr.In.URL.RawQuery
|
||||
out := pr.Out
|
||||
out.URL = &du
|
||||
out.Host = du.Host
|
||||
out.RequestURI = ""
|
||||
out.Proto = "HTTP/1.1"
|
||||
out.ProtoMajor = 1
|
||||
out.ProtoMinor = 1
|
||||
out.Header.Del("Authorization")
|
||||
if auth != "" {
|
||||
req.Header.Set("Authorization", auth)
|
||||
out.Header.Set("Authorization", auth)
|
||||
}
|
||||
},
|
||||
Transport: rt,
|
||||
Transport: rt,
|
||||
FlushInterval: -1,
|
||||
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
|
||||
errHandler(w, r, err)
|
||||
},
|
||||
@@ -70,4 +75,3 @@ func MihomoJSONError(w http.ResponseWriter, code, msg string) {
|
||||
"error": map[string]string{"code": code, "message": msg},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user