- 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.
31 lines
632 B
Go
31 lines
632 B
Go
package proxy
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// JoinPathPrefix builds the upstream URL the same way as aggregate FetchTelemtGET:
|
|
// base URL + path_prefix (e.g. /v1) + rest (e.g. health, stats/users) via url.JoinPath.
|
|
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...)
|
|
}
|