-
Notifications
You must be signed in to change notification settings - Fork 925
Support run_worker_first
in Vite plugin
#9575
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
Conversation
🦋 Changeset detectedLatest commit: 1498a8f 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 |
run_worker_first
and static routingrun_worker_first
in Vite plugin
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: |
3876562
to
5ef4d73
Compare
@@ -1,5 +1,5 @@ | |||
{ | |||
"extends": "@cloudflare/workers-tsconfig/base.json", | |||
"extends": "@cloudflare/workers-tsconfig/worker.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was necessary to prevent type errors when importing from workers-shared
as workers-shared
uses @cloudflare/worker-types
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. OK.
I think we should be able to avoid that... I'll have a think about it. But not blocking this PR.
5ef4d73
to
355cc8d
Compare
f08bae5
to
64ab9fe
Compare
@@ -1,17 +1,30 @@ | |||
import asset from "./asset.txt?no-inline"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import asset from "./asset.txt?no-inline"; | |
import assetURL from "./asset.txt?no-inline"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
import asset from "./asset.txt?no-inline"; | |
import assetPath from "./asset.txt?no-inline"; |
entryWorkerConfig.assets?.run_worker_first === true | ||
? { user_worker: ["/*"] } | ||
: resolvedPluginConfig.staticRouting; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this bit of logic into the plugin-config or asset-config files?
|
||
preMiddleware = async (req, res, next) => { | ||
// Only the URL pathname is used to match rules | ||
const request = new Request(new URL(req.url!, UNKNOWN_HOST)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? Can't you just pas req
through to each matcher?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req
is a Node.js http.IncomingMessage
. The matchers require a Request
object, even though they only use the URL pathname.
({ request }: { request: Request }) => { |
Would be nice to change this but I guess it's for consistency with the other utils (also odd that generateStaticRoutingRuleMatcher
is in the Asset Worker utils when it's only used by the Router Worker).
|
||
preMiddleware = async (req, res, next) => { | ||
// Only the URL pathname is used to match rules | ||
const request = new Request(new URL(req.url!, UNKNOWN_HOST)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally avoid ! assertions and use a runtime assertion to narrow the type:
const request = new Request(new URL(req.url!, UNKNOWN_HOST)); | |
assert(req.url, "expected request URL to be defined"); | |
const request = new Request(new URL(req.url, UNKNOWN_HOST)); |
@@ -1,5 +1,5 @@ | |||
{ | |||
"extends": "@cloudflare/workers-tsconfig/base.json", | |||
"extends": "@cloudflare/workers-tsconfig/worker.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. OK.
I think we should be able to avoid that... I'll have a think about it. But not blocking this PR.
… directly to entry Worker
64ab9fe
to
1498a8f
Compare
Fixes #8430.
Fixes #8879.
Fixes #9109.
Support
run_worker_first
and static routing.