Skip to content

fix(cloudflare): correct assets.directory in wrangler.json when base is set#16607

Merged
ematipico merged 6 commits into
withastro:mainfrom
alexanderflodin:fix/cloudflare-base-assets-directory
May 22, 2026
Merged

fix(cloudflare): correct assets.directory in wrangler.json when base is set#16607
ematipico merged 6 commits into
withastro:mainfrom
alexanderflodin:fix/cloudflare-base-assets-directory

Conversation

@alexanderflodin

Copy link
Copy Markdown
Contributor

Changes

Fixes a regression from #16277 where the generated wrangler.json sets
assets.directory to 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.ts verifying the assets directory in
the generated wrangler.json points to the un-prefixed client root.

Docs

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label May 5, 2026
@alexanderflodin alexanderflodin force-pushed the fix/cloudflare-base-assets-directory branch from ffb13fe to 4daa521 Compare May 5, 2026 14:33
@changeset-bot

changeset-bot Bot commented May 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 651d98f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@astrojs/cloudflare Patch
@test/astro-cloudflare-node-prerender-mdx Patch
@test/astro-cloudflare Patch
@test/astro-cloudflare-allowed-hosts Patch
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-binding-image-service Patch
@test/astro-cloudflare-cache-provider-wait-until Patch
@test/astro-cloudflare-client-address Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-custom-entryfile Patch
@test/astro-cloudflare-dev-image-endpoint Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-external-redirects Patch
@test/astro-cloudflare-internal-redirects Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-prerender-node-env Patch
@test/astro-cloudflare-prerender-queue-consumers Patch
@test/astro-cloudflare-prerender-styles Patch
@test/astro-cloudflare-prerenderer-errors Patch
@test/routing-priority-cloudflare Patch
@test/cf-server-entry Patch
@test/astro-cloudflare-server-island-prerender-framework Patch
@test/astro-cloudflare-sessions Patch
@test/astro-cloudflare-sql-import Patch
@test/cf-ssr-deps Patch
@test/astro-cloudflare-static Patch
@test/astro-cloudflare-svelte-rune-deps Patch
@test/astro-cloudflare-top-level-return Patch
@test/astro-cloudflare-vite-plugin Patch
@test/astro-cloudflare-with-base Patch
@test/astro-cloudflare-with-react Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-with-svelte Patch
@test/astro-cloudflare-with-vue Patch
@test/astro-cloudflare-wrangler-preview-platform Patch

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

@kitschpatrol

Copy link
Copy Markdown
Contributor

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.

@alexanderflodin

Copy link
Copy Markdown
Contributor Author

@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 ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely correct. The file could exist but JSON.parse might fail.

Comment thread packages/integrations/cloudflare/src/index.ts
@alexanderflodin alexanderflodin requested a review from ematipico May 20, 2026 12:08

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need to reword the changeset

Comment thread .changeset/wacky-cities-raise.md Outdated
@ematipico ematipico merged commit 98297af into withastro:main May 22, 2026
24 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants