This commit is contained in:
simonpetit 2025-01-06 17:00:50 +00:00
parent 09f22af85b
commit b477ad02be

View File

@ -19,9 +19,9 @@ func main() {
// Parse the API URL
r.Handle("/cats/*", reverseProxy("https://catfact.ninja"))
r.Handle("/cats/*", reverseProxy("https://catfact.ninja", "/cats"))
r.Handle("/coins/*", reverseProxy("https://api.coindesk.com/v1/bpi"))
r.Handle("/coins/*", reverseProxy("https://api.coindesk.com/v1/bpi", "/coins"))
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("root."))
@ -46,7 +46,7 @@ func reverseProxy(target string, prefixToStrip string) http.Handler {
// Rewrite the request path by stripping the prefix
originalPath := r.URL.Path
strippedPath := strings.TrimPrefix(originalPath, prefixToStrip)
log.Printf("stripped path %s", strippedPath)
// Update the proxied request URL
r.URL.Path = strippedPath // Use the stripped path in the proxy
r.URL.Scheme = parsedURL.Scheme