Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/runtime/presets/cloudflare/database-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export default eventHandler(async (event) => {

const ASSETS = event?.context?.cloudflare?.env.ASSETS || process.env.ASSETS
if (ASSETS) {
const config = event?.context?.nitro?.runtimeConfig
const url = new URL(event.context.cloudflare?.request?.url || 'http://localhost')
url.pathname = `/dump.${collection}.sql`
url.pathname = `${config?.app?.baseURL || '/'}dump.${collection}.sql`
Copy link

Choose a reason for hiding this comment

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

Suggested change
url.pathname = `${config?.app?.baseURL || '/'}dump.${collection}.sql`
url.pathname = `/dump.${collection}.sql`

The code incorrectly includes baseURL in the public asset pathname, which will cause asset fetches to fail in Cloudflare deployments that have a non-root baseURL configured.

View Details

Analysis

Incorrect baseURL prefix in Cloudflare database handler causes asset fetch failures

What fails: database-handler.ts in Cloudflare preset incorrectly includes baseURL prefix when constructing asset path, causing ASSETS.fetch() to request dump files from wrong location

How to reproduce:

  1. Deploy Nuxt Content app to Cloudflare with baseURL: '/app/' configured
  2. Access any route that triggers database handler (e.g., collection queries)
  3. Handler attempts to fetch from /app/dump.collection.sql instead of /dump.collection.sql

Result: Returns 404 response as text instead of SQL dump data, breaking data loading for collections

Expected: Assets should be fetched from root path /dump.collection.sql where publicAssets are served by Cloudflare, regardless of baseURL setting per Nitro publicAssets documentation

Root cause: publicAssets are served from root path by Cloudflare Workers/Pages static asset serving, but handler incorrectly applies app.baseURL prefix to asset pathname construction

return await ASSETS.fetch(url).then((r: Response) => r.text())
}

Expand Down
Loading