environment variable

I defined a Environment Variables on the dashboard Variable name = SERVER_URL, Value = server.xxx.com In my code I use const serverURL = env.SERVER_URL or ENV.SEREVER_URL to call this variable that was defined on the dashboard but the console will show env, ENV is not defined. Then I try using const serverURL = process.env.SERVER_URL, console will show Server URL : undefined. How can I call SERVER_URL that was defined on the dashboard?
5 Replies
Hello, I’m Allie!
env is defined on the ContextObject of a Function
JustDev
JustDevOP12mo ago
Could you give me a document or example of how to call SERVER_URL ?
Cyb3r-Jak3
Cyb3r-Jak312mo ago
Also if you defined in the dashboard, they won’t be available in local mode with Pages.
Cyb3r-Jak3
Cyb3r-Jak312mo ago
Bindings · Cloudflare Pages docs
A binding enables your Pages Functions to interact with resources on the Cloudflare developer platform. Use bindings to integrate your Pages Functions …
JustDev
JustDevOP12mo ago
I'm not clearly understand after reading a document. Can I use const serverURL = context.env.SERVER_URL ? I tried using this code export function onRequest(context) { if (context.env.SERVER_URL === 'development') { return new Response('This is a local environment!'); } else { console.log('serverURL', SERVER_URL); return new Response(SERVER_URL); } } but the result was Uncaught TypeError: Cannot read properties of undefined (reading 'env')
Want results from more Discord servers?
Add your server