Skip to content
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

Proxy configuration at sub-route #193

Open
jtbaker opened this issue Nov 6, 2023 · 2 comments
Open

Proxy configuration at sub-route #193

jtbaker opened this issue Nov 6, 2023 · 2 comments

Comments

@jtbaker
Copy link

jtbaker commented Nov 6, 2023

Hi, thanks for the great tool!

I have a use case where I'd like to proxy a pg_tileserv deployment at a sub-route of my app, something like /tiles to be able to use its built in authentication functionality. I'm sure I'm not the only person that may use this pattern, and the machine-readable json endpoints are quite helpful.

Using the Forwarded, X-Forwarded-Host and X-Forwarded-Scheme headers works great for proxying to another bare route, updating the detailurl properties to have the right origin. But if I want those values to be mapped to my sub-route, the logic breaks down and I have to do some parsing/reinjection of the properties returned in the .json endpoints to change the route to include my proxied sub-route.

Could I do this using some some sort of HTTP header information that I attach in my proxied requests? It looks like it only respects the Host property and strips anything after that at the moment.

Example header:

Forwarded: host="localhost:8000/tiles/";proto=http

/index.json returns objects like this:

...
detailurl: http://localhost:8000/public.<table_name>.json

instead of

detailurl: http://localhost:8000/tiles/public.<table_name>.json
@pramsey
Copy link
Collaborator

pramsey commented Nov 6, 2023

Have you played with

# Advertise URLs relative to this server name
# default is to look this up from incoming request headers
# UrlBase = "http://localhost/"

# Optional path to add to the service base URL
# If set, all routes will be prefixed with this path
# BasePath = "/"

https://github.com/CrunchyData/pg_tileserv/blob/master/config/pg_tileserv.toml.example

@wendellwt
Copy link

I had the same issue when the server was behind a proxy that rewrites the address. Setting BasePath looked right, but BasePath was used in other places that broke things. UrlBase didn't work either when it ended with a path name (in addition to the fqdn part).
The only way I was able to get it to work was to edit util.go near line 44 to force the return of the desired url:

func formatBaseURL(baseHost string, basePath string) string {
        ...
        return "https://myserver.com/tiles"
}

Not pretty, but it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants