dedboi
Explore posts from serversnuxt/nitro cloudflare pages bundling issue
Hi, I'm working on a full stack web app using nuxt3 for the frontend and nitro for the backend.
My app works as intended in development. However. When i build it for cloudflare pages using nitro presets and I run it with
wrangler pages dev dist/
I have 2 endpoints that are problematic: /api/user/me and /api/user/repositories/list
Both gets data from github api, (i tried with octokit.js and $fetch).
However:
After building for cloudflare pages. It seems that only one or the other endpoint works.
I get the errors:
When using octokit on the server:
"Object prototype may only be an Object or null: undefined",
When using $fetch on the server:
403 Forbidden
-> cf pages runtime seems to strip my user agent and the request fails. on development and production
For the 1st error, i tried returning functions and clean types everywhere but it never seems to work once bundled for cloudflare pages.
Could anyone help me on this one ? I checked a lot of the docs of nuxt, nitro, wrangler and cloudflare pages and can't seem to find much to debug this one and it seems to point out to a bundling/build issue with nitro imo !
code snippets here 🙂 : https://gist.github.com/mickaelicoptere/c40d9bff314721e9c3fb3602926318d6
Cheers1 replies
CDCloudflare Developers
•Created by dedboi on 4/23/2024 in #pages-help
Cloudflare pages build/bundling issue
My app works as intended in development. However. When i build it for cloudflare pages using nitro presets and I run it with
wrangler pages dev dist/
I have 2 endpoints that are problematic: /api/user/me and /api/user/repositories/list
Both gets data from github api, (i tried with octokit.js and $fetch).
However:
After building for cloudflare pages. It seems that only one or the other endpoint works.
I get the errors:
When using octokit on the server:
"Object prototype may only be an Object or null: undefined",
OR
When using $fetch on the server:
403 Forbidden
-> cf pages runtime seems to strip my user agent and the request fails. on development and production
If this error happens on /api/user/repositories/list, my endpoint /api/user/me is working and vice versa..
For the 1st error, i tried returning functions and clean types everywhere but it never seems to work once bundled for cloudflare pages.
Could anyone help me on this one ? I checked a lot of the docs of nuxt, nitro, wrangler and cloudflare pages and can't seem to find much to debug this one and it seems to point out to a bundling/build issue with nitro imo !
code snippets here 🙂 : https://gist.github.com/mickaelicoptere/c40d9bff314721e9c3fb3602926318d6
Cheers1 replies