fix(cloudflare): correct assets.directory in wrangler.json when base is set#16607
Conversation
ffb13fe to
4daa521
Compare
🦋 Changeset detectedLatest commit: 651d98f The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 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 |
|
I'm running into this issue as well, currently working around it with a very ugly integration hook. Hope this can get a review soon. |
|
@kitschpatrol thanks for confirming it's not only me struggling with this 😅 Since Astro 6 (using the Cloudflare adapter) I've been running scripts post-build to patch things up and I initially thought my issues would go away when #16607 got merged but it seems like it only solved part of the problem. I never got around to create an issue before setting up the PR so maybe thats why it hasn't gotten reviewed yet 🤔 (so if you have set one up feel free to link to this PR). Hopefully someone takes a look soon 🤞 |
ematipico
left a comment
There was a problem hiding this comment.
I don't think the current code is correct. I added some comments
| await writeFile(wranglerJsonUrl, JSON.stringify(wranglerConfig)); | ||
| } | ||
| } catch { | ||
| // wrangler.json may not exist |
There was a problem hiding this comment.
Not entirely correct. The file could exist but JSON.parse might fail.
ematipico
left a comment
There was a problem hiding this comment.
Looks good, just need to reword the changeset
Changes
Fixes a regression from #16277 where the generated
wrangler.jsonsetsassets.directoryto include the base prefix (e.g."../client/blog"instead of
"../client").Cloudflare's asset binding resolves the full request URL path (including
the base) against the directory. With the prefixed path, requests would
resolve to a double-nested location (e.g.
client/blog/blog/file.js),causing 404s for all static assets.
Related: #16276
Testing
Added a test to
with-base.test.tsverifying the assets directory inthe generated wrangler.json points to the un-prefixed client root.
Docs