-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple domains in CORS in pmtiles serve
#191
Comments
This is intentionally limited to a single origin, because that CORS feature is intended only for development. If you need multiple CORS origins you should use a reverse proxy like Caddy or Nginx that already supports multiple origins via configuration. |
@bdon , thanks for answering. You are right, it makes more sense to do CORS handling elsewhere. It's just too handy to only use your Docker container in Google Cloud Run. For me, the least-amount-of-effort solution for multiple-CORS is to extend the code, keep local fork, build and push Docker container and just change the container image name in your GCP walkthrough: Thanks for the work on pmtiles and feel free to close this. |
Just passing this along FYI: CORS support was added to the sfomuseum/go-sfomuseum-pmtiles wrapper that we use to serve pmtiles (using the rs/cors package). |
It seems reasonable to add multiple CORS support via https://github.com/rs/cors, I imagined many use cases that use go-pmtiles are going to use a CDN in front, @t0mk are you accessing the Cloud Run directly from the browser with no caching in between? |
Yes, I access the cloud run service directly. For the time being it's good enough for me, I'm still experimenting - deciding if I should host tiles myself with pmtiles or just pay for Stadia map. I could configure loadbalancer with CDN, but I don't want to use (or even activate) Compute. I think I could configure CORS with the Google Cloud Loadbalancer. |
@t0mk @thisisaaronland here is a quick spike on using This does clean up our own server code quite a bit. |
When serving tiles, it's sometimes useful to whitelist CORS "access" from more than one domain (but not from everywhere). It would be helpful for me if this was possible with pmtiles.
Since response header
Access-Control-Allow-Origin
only allows to specify one domain name, I think the server code could checkOrigin
header from request, and if it would be one of the whitelisted origins, it would copy it toAccess-Control-Allow-Origin
in response.The whitelisted CORS origins could be listed in the
--cors
argument, just comma-separated. For example:pmtiles serve ./ --cors="https://mydomain.com,https://otherdomain.com"
I could contribute this. Would you be interested in taking it in?
The text was updated successfully, but these errors were encountered: