Refactor reverse proxy to support API base path and update example configuration. Changed base URLs in config.example.yaml to use HTTPS and the new /api/ prefix. Enhanced reverse proxy logic in reverse.go to build upstream paths correctly and added a new test for path rewriting with the API base path in reverse_test.go.
Publish telemt-api gateway Docker image / test (push) Successful in 32s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 1m40s

This commit is contained in:
Denozordec
2026-03-30 00:04:45 +07:00
parent e58f504395
commit 16b1d8148d
3 changed files with 70 additions and 14 deletions
+21
View File
@@ -24,3 +24,24 @@ func TestReverseProxyPathRewrite(t *testing.T) {
t.Fatalf("status %d", rec.Code)
}
}
func TestReverseProxyPathRewriteWithAPIBasePath(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/health" {
t.Fatalf("path %q", r.URL.Path)
}
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
up, err := url.Parse(srv.URL + "/api/")
if err != nil {
t.Fatal(err)
}
rp := NewReverseProxy(up, "/api/main_srv", "/v1", "")
req := httptest.NewRequest(http.MethodGet, "/api/main_srv/health", nil)
rec := httptest.NewRecorder()
rp.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status %d", rec.Code)
}
}