-
-
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
Serve from the path of the public hostname #61
base: main
Are you sure you want to change the base?
Conversation
Passing public-hostname with a non-empty path will use that path as the prefix for the HTTP handler. This is technically a breaking change, in that anybody who was using a non-empty path behind a reverse proxy must have had it configured to remove the path prefix on that end. Now they need to remove that. However, that's generally a brittle thing to do; it's simpler all around for the backend server to know what its root path should be. Moreover, Firebase Hosting doesn't have such a capability, so it would require running an additional backend server.
The intention before was for If you have Can you link to how this is deployed to Firebase Hosting so I can reproduce it? |
Really, I was surprised when I was trying to get this to work. I supplied the public URL on the command line, and the server did not respond to that URL. Having to actually remove the prefix at the proxy layer is weird. For instance, there could be no proxy, just running on an external port, but we still need to tell the server what its hostname is, so accepting a path as part of that option, but ignoring it, is weird. I think it is pretty standard for the external URL flag to alter the URL paths that the backend accepts, and not to require the user to remove them at the proxy. I'm not aware of a useful guide "how to write a well-behaved web backend", but it's my conviction that this is the correct way. https://github.com/prometheus/prometheus/blob/1b9a53b5eea62e82a65bb65a8139c38dbd8f259e/cmd/prometheus/main.go#L266-L272 Anyway, the Firebase setup isn't checked in anywhere, but it looks like this:
Running a version of the server which contains this patch. Firebase can match a glob or regex and dispatch it to a Cloud Run, and that's it. My file -- https://asdf-f6040.web.app/tiles/NationalFile.json (Perhaps related, the positional path argument and the bucket flag seem mutually exclusive? Hard to say) There's also no index page to say yes, you correctly reached the server's homepage; that would require a bucket scan operation of course, but an empty filename could perhaps instead return "Hello, go-pmtiles!" since that can't possible match anything real. There are other routing approaches, e.g. https://github.com/consbio/mbtileserver/blob/c4c18f5b60c22559df36c1c57db1d22d17415f5b/main.go#L98 allows configuring the path prefix only, and determines its hostname on the fly via https://github.com/maplibre/martin/blob/550a46bd0f58c6a7054f121bf103cf9e886fcd47/demo/frontend/nginx.conf#L69 seems to encourage removing the url prefix at the proxy and adding the original in an |
OK, thanks for the detail. This dovetails with protomaps/PMTiles#174 since it looks like Firebase Deploy is just Google Cloud Run? I'll give it a spin myself soon
If we automatically derive the hostname via |
Firebase Hosting can be paired with either Cloud Functions or Cloud Run, and can also serve static content.
Mainly because the configuration doesn't quite line up. Google Cloud has a few options but in my opinion, Cloud Run + Firebase Hosting is cheap and simple. (For instance, AWS Lambda supports the JavaScript version as native, but Cloud Functions sort of has a long build step that turns it into a container image. Cloud Run can deploy any HTTP service while AWS Lambda requires an accompanying host that connects to a special endpoint to shuttle requests.) And I don't actually want to map my Cloud Run Service to a domain, I want a CDN, in order to minimize the container startup latency, bucket latency, etc. The Google options are Cloud CDN and Firebase Hosting. The latter has a generous free tier; the former has none, so that determines my choice. However, the way Firebase Hosting works is "one per project", as opposed to a resource that you can create n of. So for "all my ad-hoc hobby cloud stuff", I would configure it in this way.
Yes, that's a great workaround, if a bit unintuitive without a nice tutorial to follow.
For sure. I'd probably go with externalUrl as a single flag.
Right, it would require adding a |
@jleedev has this been running pretty well for you? My plan is to knock out some docs related to both GCP and running |
Yes, it seems to work fine.
|
Related https://github.com/orgs/protomaps/discussions/1 for potentially loading go-pmtiles as a caddy module I need to investigate if this lets Caddy handle URL prefixes while the pmtiles HTTP handler is prefix-unaware. Caddy may also be able to pass the correct path and hostname (it has it for Let's Encrypt) |
see #85 for directly related discussion of prefixes and tilejson hostnames |
basic Google Cloud Run instructions up: https://docs.protomaps.com/deploy/google-cloud This deployment pattern is straightforward compared to Firebase but doesn't yet include the Cloud CDN component |
Passing public-hostname with a non-empty path will use that path as the prefix for the HTTP handler.
This is technically a breaking change, in that anybody who was using a non-empty path behind a reverse proxy must have had it configured to remove the path prefix on that end. Now they need to remove that. However, that's generally a brittle thing to do; it's simpler all around for the backend server to know what its root path should be.
Moreover, Firebase Hosting doesn't have such a capability, so it would require running an additional backend server.