YoYo
YoYo
CDCloudflare Developers
Created by YoYo on 1/29/2025 in #pages-help
API routes in nextjs is not running and giving "no such module" error
I have a nextjs project which is using next on pages to build it for the cloudflare pages platform. I followed the documentation here: https://developers.cloudflare.com/pages/framework-guides/nextjs/ssr/get-started/ I am also using D1 as my database. Running the development server, I can send requests to my /api/waitlist route, where waitlist is the route defined, and I am able to save data to my local D1 correctly. The problem comes when I run a build preview using this package.json script: "preview": "npm run cfbuild && wrangler pages dev --port 3005". It builds the project perfectly fine and I am using the experimental-edge runtime. When the wrangler dev server starts and I make a request to my /api/waitlist route, it is throwing the following error:
[wrangler:inf] POST /api/waitlist 500 Internal Server Error (52ms)
✘ [ERROR] [Error: No such module "__next-on-pages-dist__/functions/api/async_hooks".

imported from "__next-on-pages-dist__/functions/api/waitlist.func.js"]
[wrangler:inf] POST /api/waitlist 500 Internal Server Error (52ms)
✘ [ERROR] [Error: No such module "__next-on-pages-dist__/functions/api/async_hooks".

imported from "__next-on-pages-dist__/functions/api/waitlist.func.js"]
I don't know why I am getting this error and how do i fix it? Please help. I am using this version of "@cloudflare/next-on-pages": "^1.13.7", in my package.json.
1 replies
CDCloudflare Developers
Created by YoYo on 11/3/2024 in #general-help
How do I route cloudflare pages through my nginx proxy which is hosted locally using cloudflared?
I have a web app hosted on cloudflare pages and I have my other services running in a docker network with nginx as the reverse proxy locally which is being tunnelled using cloudflare tunnel to a wildcare domain name *.example.com. I am able to access all my other services as you can see in the template below like api.example.com, search.example.com but whenever I go app.example.com which is supposed to proxy to my cloudflare pages, I get a 400 bad request page. How do i resolve this? Is it happening because of the ssl certificates I am using as the certificates being used in my nginx proxy are locally signed ssl certificates. I have been struggling with this. Can anyone please help me?
3 replies
CDCloudflare Developers
Created by YoYo on 11/2/2024 in #pages-help
How to proxy a cloudflare hosted pages app to show on my subdomain which is managed by nginx?
I have a cloudflare pages app, let's call it dashboard.pages.dev. I am using nginx as my reverse proxy. Let's say my main server where nginx is running and managing requests is accessible on the domain example.com. I want to access my pages app on a subdomain of example.com . How do i do that? I am using the following configuration for the pages app like so:
4 replies
CDCloudflare Developers
Created by YoYo on 8/24/2024 in #workers-help
How to deploy next app using cloudflare workers?
I know that cloudflare offers pages for easy deployment of next. I cannot use pages because my repo is not hosted on github/gitlab. I looked at next-on-pages project and I am building my project using next-on-pages as the build command in my script which creates a .vercel directory and I have setup the main file of the worker correctly as well. This is my wrangler.toml file:
name = "dashboard"
type = "javascript" # or "module" if you are using the modules syntax
main = ".vercel/output/static/_worker.js/index.js"

compatibility_date = "2024-08-24"
compatibility_flags = [ "nodejs_compat" ]

[site]
bucket = ".vercel/output/static"

[env]
workers_dev = true # or false if you're deploying to a custom domain

[build]
command = "npm run cfbuild"
name = "dashboard"
type = "javascript" # or "module" if you are using the modules syntax
main = ".vercel/output/static/_worker.js/index.js"

compatibility_date = "2024-08-24"
compatibility_flags = [ "nodejs_compat" ]

[site]
bucket = ".vercel/output/static"

[env]
workers_dev = true # or false if you're deploying to a custom domain

[build]
command = "npm run cfbuild"
where cfbuild is my custom script. I deploy this project to workers using wrangler deploy and the deployment happens correctly but when I visit the worker link, I am getting Internal Server Error. How do i fix it?
10 replies