Queue consumer from nextjs worker
I'm trying to figure out what the project structure would look like if you're using the nextjs framework and you're deploying to workers.
Supposedly, worker nextjs should support effectively all services (creating durable objects, workflows, service bindings).
But where would all of those worker specific files be located? They wouldn't be in the app/api/[route] for nextjs backend routes. Do people just make a seperate folder at the root for all "worker functions"? Any examples people can point to?
1 Reply
Ah, so after some reading and asking perplexity, it seems like the following is the correct answer.
In this structure:
1. The
next-app
directory contains your Next.js application.
2. The workers
directory contains separate directories for each Cloudflare Worker.
3. Each Worker has its own wrangler.toml
file for configuration.
4. The Next.js app's wrangler.toml
would include service bindings to the Workers.
For example, in the Next.js app's wrangler.toml
:
Then, in your Next.js API routes, you can use these service bindings. For example, in pages/api/user.js
:
This structure allows you to separate concerns between your Next.js app and various Cloudflare Workers, while still enabling efficient communication between them through service bindings