tloncorp / landscape

13 stars 16 forks source link

landscape: add public url base to S3 configuration #252

Closed mrdomino closed 8 months ago

mrdomino commented 8 months ago

landscape: add public url base to S3 configuration

This enables using Cloudflare R2 as a storage provider.

Cloudflare R2 is an S3-compatible API with a generous free tier; it looks like it may cost nothing for most Urbit ships’ usage patterns. The only hitch is that R2’s endpoint is not able to be configured to be publicly readable; in order to make a bucket public, you must either use an r2.dev URL, or set up your own custom URL. Caching and such is only supported on your own URL, so it sounds like that’s the case they’re encouraging people to target.

This change enables R2 support by adding a configuration option to set a public URL base. If it is non-empty, it replaces the origin for any S3 upload URLs. A ship may use either its r2.dev URL or a custom URL at its discretion. As a nice side benefit, this also allows wrapping S3 access over a custom domain that you control, allowing you to configure caching, mirroring, or a CDN of your own.

mrdomino commented 8 months ago

Updated the description to be more clear about why this is desirable.

As mentioned on the other PR I have not been able to actually test this, as I have not been able to figure out how to actually load the changed JavaScript from both desks into a development server. But I have confirmed that both Arvo and the Remote Storage configuration form work properly.

mrdomino commented 8 months ago

Now does not include the bucket name in the resultant URL if using publicUrlBase. This should work for R2.

Note that publicUrlBase does not currently support any path components; it will just take the origin and use that. This is just enough to get R2 working; if more functionality is desired, it can be added later.

mrdomino commented 8 months ago

(Would love it if someone could show me how to test this, or else test it themselves.)

mrdomino commented 8 months ago

Ok, successfully tested this and confirmed that it behaves as expected both with and without publicUrlBase configured.