bluesky / tiled

API to structured data
https://blueskyproject.io/tiled
BSD 3-Clause "New" or "Revised" License
60 stars 52 forks source link

Support serving Tiled from a sub-path. #283

Open danielballan opened 2 years ago

dylanmcreynolds commented 2 years ago

A common use case for this is combining tiled with other services and UI apps behind a single reverse proxy server (nginx, k8s ingress nginx, traefik, etc.)

Say you had a user interface that accessed tiled for some or all of its data. You would want several routes that your reverse proxy server could use for dispatching requests:

This is really difficult to do today, because tiled can only process requests to /. The only solution that I know of here is to setup the reverse proxy to expose /tiled for external services (making it the public-facing url for tiled) and then re-write the path in every request before sending to tiled. This is a lot of work and gets confusing.

It would be better if we could configure the root path that tiled responds to.

danielballan commented 1 year ago

For Future Us, remember this comment suggesting a way forward here: https://github.com/bluesky/tiled/pull/347#issuecomment-1410934348

danielballan commented 10 months ago

Addressed by https://github.com/bluesky/tiled/pull/646 but needs docs. A working nginx config is over in https://github.com/bluesky/bluesky-pods/pull/37.

tacaswell commented 10 months ago

To be fair, #646 just makes it possible to configure the whole thing to sit behind nginx with no extra re-writing. The thing it does not do is move the /ui to / and the landing page with hints off to someplace else.

dylanmcreynolds commented 9 months ago

I'm now confused.

With #646, can I somehow mount all of tiled to, say, http://localhost/tiled and see both the ui homepage run at that URL, and point the python tiled client to that URL? If so, I'm super excited.

tacaswell commented 9 months ago

The ui is at http://localhost/tiled/ui and the API is at http://localhost/tiled/api

dylanmcreynolds commented 9 months ago

And is tiled configurable? Could the by http://localhost/toms_awesome_data_server/ui?

tacaswell commented 9 months ago

yes.

With the right nginx config (and a second tiled instance) you could even have http://localhost/toms_awesome_data_server/ui and http://localhost/dylans_awesome_data_server/ui running next to each other.

danielballan commented 9 months ago

Config, lifted from https://github.com/bluesky/bluesky-pods/pull/37:

        location ^~ /tiled/ {
            proxy_pass          http://tld:8000/;
            proxy_read_timeout 60s;

            # May not need or want to set Host. Should default to the above hostname.
            proxy_set_header          Host            $host;
            proxy_set_header          X-Forwarded-Host $host:11973;
            proxy_set_header          X-Real-IP       $remote_addr;
            proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
        }
tacaswell commented 9 months ago

should probably use $server_port rather than a hard-coded port number