Skip to content

Commit

Permalink
feat: asset serving config for workers + assets (#6631)
Browse files Browse the repository at this point in the history
* add asset config behaviour

move shared assets code to workers-shared/utils

add asset config to wrangler

add asset config to miniflare

add config binding to asset-worker

add asset config behaviour to AW (this is the big one)

make UW manually handle 404s

update assets-only fixture

fix drop-trailing-slash logic

html handling tests

* pr feedback

* fix tests and pr feedback 2

* changesets

---------

Co-authored-by: Samuel Macleod <smacleod@cloudflare.com>
Co-authored-by: Greg Brimble <gbrimble@cloudflare.com>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent 7bbed63 commit 59a0072
Show file tree
Hide file tree
Showing 58 changed files with 2,201 additions and 400 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-pears-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add config options 'html_handling' and 'not_found_handling' to experimental_asset field in wrangler.toml
9 changes: 9 additions & 0 deletions .changeset/real-cheetahs-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@cloudflare/workers-shared": minor
---

Add asset config behaviour.

Add `html_handling` (e.g. /index.html -> /) with options `"auto-trailing-slash" | "force-trailing-slash" | "drop-trailing-slash" | "none"` to Asset Worker.

Add `not_found_handling` behaviour with options `"404-page" | "single-page-application" | "none"` to Asset Worker.
5 changes: 5 additions & 0 deletions fixtures/asset-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Asset config fixture

This is testing the asset worker in the workers-shared package. We cannot use the vitest integration directly in that package because it results in circular dependencies.

Since it runs tests in a workerd context and doesn't depend on the host OS, this fixture only runs test on Linux to reduce wasted time in CI.
8 changes: 8 additions & 0 deletions fixtures/asset-config/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module "cloudflare:test" {
// Controls the type of `import("cloudflare:test").env`
interface ProvidedEnv {
CONFIG: Record<string, string>;
ASSETS_MANIFEST: ArrayBuffer;
ASSETS_KV_NAMESPACE: KVNamespace;
}
}
Loading

0 comments on commit 59a0072

Please sign in to comment.