Running functions / inject variables on edge #566
-
Hello, I am pretty new to NextJS but not on Cloudflare Pages. Unfortunately, even though I (kind of) understand in general how you made NextJS work on Pages (by uploading a worker and using /functions), I cannot understand if it's possible to use /functions myself as well. Why? Because I usually used /functions to inject variables into static pages and do other changes. In this example, from what I understand the pages are rendered using edge runtime. This makes it impossible for me to use my own functions, as I have tried to place /functions folder in several places along the project but it never gets picked up. I need to inject variables into several pages, for example:
I have also tried to move this page to I have read about Data Fetching but this is not a viable solution, and again it does not compile. Ideal solution is to simply call an internal function and inject the variable into the page, on the server side. If there is a method to use /functions or anything else I am not aware of, please do share. My project will die without this ability. Many Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Anyone? :( |
Beta Was this translation helpful? Give feedback.
-
Not sure what you mean by injecting stuff but you cannot use the functions directory with next-on-pages. You should be using Next.js' API routes + middleware instead of using the functions directory. If you have problems building your app, maybe you could share those errors? |
Beta Was this translation helpful? Give feedback.
Why do you need access to request? Next.js has utility functions for
headers()
andcookies()
that you should be using instead in server components.https://nextjs.org/docs/app/api-reference/functions/headers
https://nextjs.org/docs/app/api-reference/functions/cookies