Direct R2 assets

This commit is contained in:
2026-06-21 08:14:57 -04:00
parent 72731306ff
commit 99a6a294ba
6 changed files with 104 additions and 26 deletions
+24
View File
@@ -52,6 +52,30 @@ CF_WORKER_NAME=swansea-airfield-test
For Directus, use public HTTPS URLs in Worker env files. Do not use Docker-only hostnames such as `http://directus:8055` outside Docker Compose.
## Directus Assets From R2
Local development can keep using Directus asset URLs. For test and production Worker builds, set one of these optional values in `.env.worker.test` and `.env.worker.prod` to make the generated Astro HTML point at R2-hosted files instead:
```env
DIRECTUS_ASSET_BASE_URL=https://assets.swansea-airport.wales/
```
With `DIRECTUS_ASSET_BASE_URL`, a Directus file ID such as `abc-123` becomes:
```text
https://assets.swansea-airport.wales/abc-123.jpeg
```
The extension comes from Directus `filename_download`, so R2 object keys should use the pattern `<directus-file-id>.<extension>`.
If the R2 public URL needs a custom path shape, use a template instead:
```env
DIRECTUS_ASSET_URL_TEMPLATE=https://assets.swansea-airport.wales/directus/{id}
```
`DIRECTUS_ASSET_URL_TEMPLATE` takes priority over `DIRECTUS_ASSET_BASE_URL`. The template supports `{id}`, `{key}`, and `{fileId}` as aliases for the R2 object key, usually Directus `filename_disk`. Leave both unset in local `.env` to keep using `DIRECTUS_PUBLIC_URL/assets/<id>`.
## Build Locally For Test
When working through Docker Compose: