nilsnolde / docker-valhalla

This is our flexible Docker repository for the Valhalla routing engine
MIT License
257 stars 74 forks source link

Issue with CORS #172

Open RajaShanmugamJM opened 2 weeks ago

RajaShanmugamJM commented 2 weeks ago

My findings

  1. CORS is not allowed by valhalla
  2. OPTIONS method is throwing error

I wasted entire day trying to find a work around.

Steps attempted

  1. Adding proxy and removing CORS header before proxying
  2. Adding proxy to resolve OPTIONS method automatically
  3. Making sure both front-end and back-end are in same domain ( in different sub-domains )
  4. Tried almost all the CORS extension on chrome.

Proxied using Caddy, (Config file attached below. Tried without proxy too)

Attempt 1:

https://valhalla.localhost {
    handle /api {
        rewrite /api /
        reverse_proxy http://localhost:8002
    }

    handle /ui {
        reverse_proxy http://localhost:5173
    }
}

Attempt 2:

https://valhalla.localhost {
    reverse_proxy http://localhost:8002
}

https://ui.valhalla.localhost {
    reverse_proxy http://localhost:5173
}

Attempt 3

https://valhalla.localhost {
    handle / {
        reverse_proxy http://localhost:8002 {
            # Remove CORS headers (adjust as needed)
            header_down Access-Control-Allow-Origin
            header_down Access-Control-Allow-Methods
            header_down Access-Control-Allow-Headers
        }
    }

    handle /* {
        method OPTIONS
        respond 200
    }
}

If anyone had chance of bypassing this issue, your advise is highly appreciated

Originally posted by @RajaShanmugamJM in https://github.com/nilsnolde/docker-valhalla/issues/34#issuecomment-2468688400