I'm trying to deploy a Nuxt 4 project which works, but functions folder is not being served

I have
// wangler.toml
name = "<project>"
compatibility_date = "2025-09-29"

main = "functions/api/worker/index.js"

[site]
bucket = ".output/public"
// wangler.toml
name = "<project>"
compatibility_date = "2025-09-29"

main = "functions/api/worker/index.js"

[site]
bucket = ".output/public"
// functions/api/worker/index.js
import { getAssetFromKV } from "@cloudflare/kv-asset-handler"
import * as auth from "./auth.js"
import * as callback from "./callback.js"

export async function onRequest(context) {
const url = new URL(context.request.url)
const pathname = url.pathname

// Handle API endpoints
if (pathname.startsWith("/api/worker/auth")) {
return auth.onRequest(context)
}

if (pathname.startsWith("/api/worker/callback")) {
return callback.onRequest(context)
}

// Everything else serves the static site
try {
return await getAssetFromKV(context)
} catch (err) {
// If not found, fall back to SPA index.html
if (err.status === 404) {
return await getAssetFromKV(context, {
mapRequestToAsset: (req) =>
new Request(`${url.origin}/index.html`, req),
})
}
throw err
}
}
// functions/api/worker/index.js
import { getAssetFromKV } from "@cloudflare/kv-asset-handler"
import * as auth from "./auth.js"
import * as callback from "./callback.js"

export async function onRequest(context) {
const url = new URL(context.request.url)
const pathname = url.pathname

// Handle API endpoints
if (pathname.startsWith("/api/worker/auth")) {
return auth.onRequest(context)
}

if (pathname.startsWith("/api/worker/callback")) {
return callback.onRequest(context)
}

// Everything else serves the static site
try {
return await getAssetFromKV(context)
} catch (err) {
// If not found, fall back to SPA index.html
if (err.status === 404) {
return await getAssetFromKV(context, {
mapRequestToAsset: (req) =>
new Request(`${url.origin}/index.html`, req),
})
}
throw err
}
}
// my 2 functions open with
export async function onRequest(context) {
...
// my 2 functions open with
export async function onRequest(context) {
...
// package.json
"scripts": {
"submodules:init": "git config --global url.\"https://${github_PAT_TOKEN}@github.com/\".insteadOf \"https://github.com/\" && git submodule update --init --recursive",
"nuxt:build": "pnpm install && pnpm generate",
"build:cloudflare": "pnpm run submodules:init && pnpm run nuxt:build",
"deploy:cloudflare": "npx wrangler deploy",
// package.json
"scripts": {
"submodules:init": "git config --global url.\"https://${github_PAT_TOKEN}@github.com/\".insteadOf \"https://github.com/\" && git submodule update --init --recursive",
"nuxt:build": "pnpm install && pnpm generate",
"build:cloudflare": "pnpm run submodules:init && pnpm run nuxt:build",
"deploy:cloudflare": "npx wrangler deploy",
4 Replies
texan
texan2d ago
You want workers assets instead of sites: https://developers.cloudflare.com/workers/static-assets/
Tincan
TincanOP2d ago
@Will Taylor | Workers I'm getting
No event handlers were registered. This script does nothing.
13:42:35.427 [code: 10021]
No event handlers were registered. This script does nothing.
13:42:35.427 [code: 10021]
texan
texan2d ago
The code you linked doesn’t have a default handler 🙂 https://developers.cloudflare.com/workers/runtime-apis/handlers/
Tincan
TincanOP2d ago
@Will Taylor | Workers why do i have to do this now compared to in pages? I would have thought that CF with Nuxt would know to bundle the functions folder into the output. Or to at least automate this process we're doing now of manually handling the function endpoints

Did you find this page helpful?