developmentseed / titiler

Build your own Raster dynamic map tile services
https://developmentseed.org/titiler/
MIT License
765 stars 157 forks source link

Wrong protocol for factory generated URLs #727

Closed tayden closed 10 months ago

tayden commented 10 months ago

Problem description

I have an instance of Titiler running in a docker container, which is in turn proxied using Apache. The dockerized app is running under HTTP, but the Apache server serves traffic over HTTPS. Requests to https://example.com/titiler are forwarded to the docker container via Apache reverse proxy directives and the TITILER_API_ROOT_PATH environment variable setting.

When I use the /cog/viewer endpoint, data fails to load because the viewer tries to query /cog/info to get some details about the COG it's loading, but gets the protocol wrong for the URL (uses http, when it should be https). This results in a "blocked:mixed-content" error and the COG fails to load (and instead shows a spinner that never stops spinning).

Expected Output

The COG loads

Environment Information

Using Titiler 0.15.5

tayden commented 10 months ago

I think the solution to this is that the factory.url_for method (https://github.com/developmentseed/titiler/blob/main/src/titiler/core/titiler/core/factory.py#L202) needs to more carefully detect the server base_url to accommodate proxied deployments and correctly resolve the protocol. Alternatively, returning relative url paths only might work (e.g. returning /titiler/cog/info instead of https://example.com/titler/cog/info.