-
Notifications
You must be signed in to change notification settings - Fork 755
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
fix(wrangler): validate routes in dev and deploy #6621
Conversation
🦋 Changeset detectedLatest commit: a6591e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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/10814015217/npm-package-wrangler-6621 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6621/npm-package-wrangler-6621 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-wrangler-6621 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-create-cloudflare-6621 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-cloudflare-kv-asset-handler-6621 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-miniflare-6621 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-cloudflare-pages-shared-6621 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-cloudflare-vitest-pool-workers-6621 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-cloudflare-workers-editor-shared-6621 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10814015217/npm-package-cloudflare-workers-shared-6621 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
abbe295
to
cb7c7ab
Compare
if ( | ||
typeof route === "object" && | ||
hasExperimentalAssets && | ||
route.pattern.includes("/") && | ||
!route.pattern.endsWith("/*") | ||
) { | ||
invalidRoutes[route.pattern] = [ | ||
...(invalidRoutes[route.pattern] ?? []), | ||
`Routes with paths (except for the wildcard /*) are not allowed in Workers + Assets projects`, | ||
]; | ||
} |
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 handling routes with a path AND ending in /*
correctly? eg /some/path/*
– is that allowed or not?
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.
nope that should be allowed whoops - fixed
if ( | ||
typeof route === "string" && | ||
hasExperimentalAssets && | ||
route.includes("/") && | ||
!route.endsWith("/*") | ||
) { | ||
invalidRoutes[route] = [ | ||
...(invalidRoutes[route] ?? []), | ||
`Routes with paths (except for the wildcard /*) are not allowed in Workers + Assets projects`, | ||
]; | ||
} |
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 if-block is duplicated
(components.length === 2 && components[1] === "") | ||
) { | ||
invalidRoutes[pattern] ??= []; | ||
invalidRoutes[pattern].push(`Update the route to end with /*`); |
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.
Having just the action stated here might be a bit too cryptic for users. Can we also tell them what routing rule they're actually breaking here? like we do in all other places.
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.
Ah I'm not sure what the phrasing should be - i stole this one from dash. tacking copy changes/discussion onto this https://jira.cfdata.org/browse/WC-2675
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.
Could we preserve the Workers which have static assets cannot be routed on a URL which has a path component.
prefix here? The dash has a pattern of hiding the extra informational text when displaying errors (which is why it's so terse), but at the point that error is shown in dash that user should have been able to read the informational text.
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.
Ah yes, I just commented on this above. I agree it is not ideal copy.
(components.length === 2 && components[1] === "") | ||
) { | ||
invalidRoutes[pattern] ??= []; | ||
invalidRoutes[pattern].push(`Update the route to end with /*`); |
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.
Could we preserve the Workers which have static assets cannot be routed on a URL which has a path component.
prefix here? The dash has a pattern of hiding the extra informational text when displaying errors (which is why it's so terse), but at the point that error is shown in dash that user should have been able to read the informational text.
Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path/* with /* | ||
|
||
simple.co.uk/: | ||
Update the route to end with /* |
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.
I'm slightly worried about this error message. In non-assets Workers this is a valid route, right?
So the message should be similar to those above, no?
Currently I would be a bit confused to see this message.
(components.length === 2 && components[1] === "") | ||
) { | ||
invalidRoutes[pattern] ??= []; | ||
invalidRoutes[pattern].push(`Update the route to end with /*`); |
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.
Ah yes, I just commented on this above. I agree it is not ideal copy.
if ( | ||
components.length === 1 || | ||
(components.length === 2 && components[1] === "") | ||
) { | ||
invalidRoutes[pattern] ??= []; | ||
invalidRoutes[pattern].push( | ||
`Workers which have static assets must end with a wildcard path. Update the route to end with /*` | ||
); | ||
} else if (!(components.length === 2 && components[1] === "*")) { | ||
invalidRoutes[pattern] ??= []; | ||
invalidRoutes[pattern].push( | ||
`Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /${components.slice(1).join("/")} with /*` | ||
); | ||
} |
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.
I'm not entirely sure what this is meant to do. There is a magic number 2
used. Did you intend to only consider patterns with 0 or 1 /
s (hence components.length === 1 or 2)? What if there are more segments? eg /multi/segment/path/*
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.
sorry this is slightly convoluted to avoid my mortal enemy, regex.
its 2 because the only valid route is something like [route.com, *] - if its not that it hits that error.
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.
We agreed on a call to keep the logic as-is but add comments to each condition
20ca75f
to
4c05817
Compare
We want wrangler to error if users are trying to deploy a Worker with assets, and routes with a path component. All Workers with assets must have either: - custom domain routes - pattern routes which have no path component (except for the wildcard splat) "some.domain.com/\*"
8ee1fb1
to
a6591e6
Compare
* main: Add pipeline binding to wrangler.toml (#6674) Fix Pages duplicating hash in redirects (#6680) Bradley/r2 event notification get (#6652) feat(wrangler): Add support for placement hints (#6625) fix(wrangler): Validate `routes` for Workers with assets (#6621) chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates (#6673) chore(workers-shared): Configure GitHub Actions to deploy Asset Worker (#6542) feat: experimental workers assets can be ignored by adding a .assetsignore file (#6640)
What this PR solves / how to test
Fixes WC-2484.
Also now errors if invalid route config is present in
wrangler dev
.Author has addressed the following