I am hosting a NextJS site on cloudflare pages but I can't read the environment variables.
Locally I am using in .env.local
:
NEXT_PUBLIC_API_URL=https://localhost:5001/
And reading it in code:
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
It works fine locally but when I try to set NEXT_PUBLIC_API_URL
or API_URL
in cloudflare pages environment variables the code always reads an empty string.
I am not using edge runtime, I am using static site with next export
What am I doing wrong? How can I read the env var on cloudflare pages?