Nuxt3 with D1 binding example
Hi there, I'm looking for a basic example of Nuxt3 working with a d1 database. Using the ./server/ folder instead of functions. From my understanding the binding should integrate, but I'm not finding good examples that are a straight install, configure and run. I have looked at this https://github.com/tlebeitsuk/nuxt-cloudflare-lucia example. But when I go to run it, it fails with an error that seems tricky to fix.
ERROR [worker reload] [worker init] Only URLs with a scheme in: file, data,
and node are supported by the default ESM loader. On Windows, absolute paths must be valid file://
URLs. Received protocol 'c:'
I have already got a Nuxt2 application working using the ./functions/ folder as the API. But I wanted to see if it is possible to use the native ./server/ folder hosted by nuxt for easier development.
Otherwise I need to run multiple terminals, hosting nuxt, and wrangler. Then use axios to proxy the API calls so they work on the same domain. That jus seems really complicated comparied to what I want to do. Basically I want the defineEventHandler( async (event) => {...} to pass the cloudflare d1 binding through the event.context object if possible. Running a single terminal to host it.
The command to host it would be something like this
wrangler pages dev --proxy 3000 --d1=database --persist-to \"../some-folder\" -- nuxt dev
If you have some examples that you can share I'd appreciate it. Or if I'm completely barking up the wrong tree let me know.GitHub
GitHub - tlebeitsuk/nuxt-cloudflare-lucia: A demo using Nuxt, Cloud...
A demo using Nuxt, Cloudflare Pages + D1 database and Lucia auth - tlebeitsuk/nuxt-cloudflare-lucia
0 Replies