Dagy
How To Cloudflare workers with Nuxt 3 ?
Hello community,
I’m trying to deploy a nuxt site to cloudflare. I used the nuxt starter from the cli.
But I haven’t been able to use the workers for the /server/api together with the hono library.
I get internal server error. And not functionality for the server/api
I haven’t this in my nuxt.config
export default defineNuxtConfig({
compatibilityDate: "2024-11-01",
devtools: { enabled: true },
nitro: {
preset: "cloudflare-module", // ← Correct preset here
},
modules: ["nitro-cloudflare-dev"],
vite: {
optimizeDeps: {
include: ["hono"],
},
},
});
I have this in my wrangler
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "test-1",
"compatibility_date": "2025-03-03",
"compatibility_flags": ["nodejs_compat"], // ← Required
"main": "./.output/server/index.mjs",
"assets": {
"binding": "ASSETS",
"directory": "./.output/public/"
},
"r2_buckets": [{ "binding": "BUCKET", "bucket_name": "your-bucket-name" }],
"kv_namespaces": [{ "binding": "KV", "id": "your-kv-id" }],
"d1_databases": [
{
"binding": "DB",
"database_name": "your-db-name",
"database_id": "your-db-id"
}
],
"ai": { "binding": "AI" },
"observability": { "enabled": true }
}
This my workers code:
// server/api/workers.js
import { Hono } from "hono";
const app = new Hono();
app.get("/", (c) => {
const name = c.req.query("name") || "World";
return c.json({ greeting: Hello, ${name}! });
});
export default app;
5 replies