Refactor reverse proxy and enhance API routing
Publish telemt-api gateway Docker image / test (push) Failing after 26s
Publish telemt-api gateway Docker image / build-and-push (push) Has been skipped

- Replaced the existing reverse proxy implementation with a new alias forwarding mechanism, improving path handling and request normalization.
- Updated the gateway to utilize the new forwarding approach, ensuring consistent handling of API requests and proper error management.
- Enhanced tests to validate the new routing behavior, including handling of double slashes and user endpoint requests.
- Improved documentation in GATEWAY_RUN.md to clarify the updated API routing and configuration requirements.
This commit is contained in:
Denozordec
2026-03-30 11:47:50 +07:00
parent a52dff4944
commit 374b4e0d71
7 changed files with 211 additions and 147 deletions
+2 -24
View File
@@ -7,10 +7,10 @@ import (
"io"
"net/http"
"net/url"
"strings"
"time"
"github.com/telemt/telemt-api/internal/config"
"github.com/telemt/telemt-api/internal/proxy"
)
const statsUsersPath = "stats/users"
@@ -42,7 +42,7 @@ func FetchTelemtGET[T any](ctx context.Context, client *http.Client, parsed *con
if err != nil {
return zero, UpstreamCallMeta{OK: false, Error: err.Error()}
}
target := joinPathPrefix(u, srv.PathPrefix, relPath)
target := proxy.JoinPathPrefix(u, srv.PathPrefix, relPath)
start := time.Now()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, target.String(), nil)
if err != nil {
@@ -102,28 +102,6 @@ func FetchStatsUsers(ctx context.Context, client *http.Client, parsed *config.Pa
return out
}
func joinPathPrefix(base *url.URL, pathPrefix, rest string) *url.URL {
rel := strings.Trim(pathPrefix, "/")
if rest != "" {
if rel != "" {
rel = rel + "/" + rest
} else {
rel = rest
}
}
var parts []string
for _, seg := range strings.Split(rel, "/") {
if seg != "" {
parts = append(parts, seg)
}
}
if len(parts) == 0 {
out := *base
return &out
}
return base.JoinPath(parts...)
}
func truncate(s string, n int) string {
if len(s) <= n {
return s