bug fixes

This commit is contained in:
shreyvishal
2025-06-17 14:08:28 +00:00
parent 8f357eadbc
commit 789fda2666
12 changed files with 399 additions and 98 deletions

View File

@@ -115,6 +115,7 @@ func (r *Router) loadRules(configPath string) error {
if err != nil {
return fmt.Errorf("invalid URL in rule: %w", err)
}
parsedURL.Path = joinPath(parsedURL, endpoint)
route = &model.Route{
TargetType: rule.TargetType,
URL: parsedURL,
@@ -126,6 +127,7 @@ func (r *Router) loadRules(configPath string) error {
if err != nil {
return fmt.Errorf("invalid URL in rule: %w", err)
}
parsedURL.Path = joinPath(parsedURL, endpoint)
}
route = &model.Route{
TargetType: rule.TargetType,
@@ -227,24 +229,23 @@ func handleProtocolMapping(route *model.Route, npURI, endpoint string) (*model.R
}
return &model.Route{
TargetType: targetTypeURL,
URL: &url.URL{
Scheme: route.URL.Scheme,
Host: route.URL.Host,
Path: path.Join(route.URL.Path, endpoint),
},
URL: route.URL,
}, nil
}
targetURL, err := url.Parse(target)
if err != nil {
return nil, fmt.Errorf("invalid %s URI - %s in request body for %s: %w", strings.ToUpper(route.TargetType), target, endpoint, err)
}
targetURL.Path = joinPath(targetURL, endpoint)
return &model.Route{
TargetType: targetTypeURL,
URL: &url.URL{
Scheme: targetURL.Scheme,
Host: targetURL.Host,
Path: path.Join(targetURL.Path, endpoint),
},
URL: targetURL,
}, nil
}
func joinPath(u *url.URL, endpoint string) string {
if u.Path == "" {
u.Path = "/"
}
return path.Join(u.Path, endpoint)
}