Add support for static routing to Workers Assets#9416
Conversation
🦋 Changeset detectedLatest commit: ccad014 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A Wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-wrangler-9416Prereleases for other packages:
wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-workers-bindings-extension-9416 -O ./cloudflare-workers-bindings-extension.0.0.0-v5790de821.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v5790de821.vsix
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-create-cloudflare-9416 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-kv-asset-handler-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-miniflare-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-pages-shared-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-unenv-preset-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-vite-plugin-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-vitest-pool-workers-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-workers-editor-shared-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-workers-shared-9416
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15464636933/npm-package-cloudflare-workflows-shared-9416Note that these links will no longer work once the GitHub Actions artifact expires. |
f655309 to
96c27f9
Compare
96c27f9 to
da1c46f
Compare
8801f83 to
03b286c
Compare
- When a request matches a static routing "exclude" rule, it's directly forwarded to the asset worker. - When a request matches a static routing "include" rule, it's directly forwarded to the user worker. - Otherwise, previous behavior takes over This also adds a new analytics field (double6) for what routing decision was made
vitest yelled at me and told me this should be awaited and may error in future releases
When the Router worker has static routing, the check against "Sec-Fetch-Mode: navigate" is unnecessary. We have explicit static routing to indicate whether or not we should go to a User worker or the Asset worker, and should not try and guess via usually-set browser headers This adds a new parameter to unstable_canFetch RPC method, which should be fine for backwards compatibility, and can be extended in the future if needed. This was necessary because the Asset worker checks the Request headers for Sec-Fetch-Mode to indicate if it can serve an asset (including an index.html or 404.html page based on not_found_handling), but static routing is only provided to the Router worker. Thus, we need to pass more information over RPC
Now that we're not providing this configuration via _routes.json, we can
relax some of the configuration. Much of this happens on the backend,
but some field names have been changed ("include" -> "worker",
"exclude"->"asset")
03b286c to
8e93047
Compare
|
as its on a fork, the tests were run here: #9491. however, if i used actually the same sha (so github could associate tests passing on that PR with this PR), it was still running the test on the fork 🫠 so i updated the commit message so the sha is different, it ran on the fork successfully, but now the passing tests don't get associated with the original PR. so we're going to bypass checks on this PR, but the tests did pass, somewhere 🫠 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
I went the less elegant way and checked out this PR locally, then pushed to the remote repo and PRed from my branch. This seems to have done the trick and running the tests on my PR ran the tests on this PR as well. All is 🍏 so this is ready to merge 🎉 |
|
Congratulations @matthewdavidrodgers, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cmbkzd7pe1100707jvz3ellhhz This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
For WC-3583
Implements the proposal noted here #9143
In brief: when static routing is present for a Worker with assets, routing via those static rules takes precedence. When a request is evaluated in the Router Worker, the request path is first compared to the "asset" rules (which are to be specific via "negative" rules, e.g. "!/api/assets"). If any match, the request is forwarded directly to the Asset Worker. If instead any "user_worker" rules match, the request is forwarded directly to the User Worker. If neither match (or static routing was not provided), the existing behavior takes over.
As part of this explicit routing, when static routing is present, the check against "Sec-Fetch-Mode: navigate" (to guess if this should serve an asset or go to the User Worker for not_found_handling) is disabled. Routing can be controlled by setting routing rules via "run_worker_first", and asset serving (including when an index.html or 404.html page is served) will be more simple.