Update Mihomo configuration and documentation for clarity
Publish telemt-api gateway Docker image / test (push) Successful in 28s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m10s

- 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:
Denozordec
2026-03-31 00:54:41 +07:00
parent a24fc90b39
commit ed785cb8f3
6 changed files with 46 additions and 63 deletions
+19 -15
View File
@@ -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},
})
}