fix: sanitize remoteConfigURL to prevent 400 Bad Request on bandwidth reports (#82)

When REMOTE_CONFIG was provided with a trailing slash (e.g. .../gerbil/get-config/
or .../gerbil/), the old TrimSuffix logic failed to strip /gerbil/get-config
due to the trailing slash, resulting in invalid endpoint URLs like
http://pangolin:3001/api/v1/gerbil/get-config/gerbil/receive-bandwidth.

This caused Express/Traefik to return 400 Bad Request every 10 seconds.

Fix: Robustly strip trailing slashes before and after removing legacy subpaths
(/gerbil/get-config, /gerbil/receive-bandwidth, /gerbil).

Fixes #82
This commit is contained in:
Aditya kumar singh
2026-07-21 18:13:37 +05:30
parent e25e5766df
commit f17612c5d9

View File

@@ -429,9 +429,12 @@ func main() {
logger.Fatal("You must provide either a config file or a remote config URL, not both")
}
// clean up the reomte config URL for backwards compatibility
// clean up the remote config URL for backwards compatibility
remoteConfigURL = strings.TrimRight(remoteConfigURL, "/")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/get-config")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/receive-bandwidth")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil")
remoteConfigURL = strings.TrimRight(remoteConfigURL, "/")
var key wgtypes.Key
// if generateAndSaveKeyTo is provided, generate a private key and save it to the file. if the file already exists, load the key from the file