Script does not work with environmental variables
Hi, I am using this function to get contact form submit data and send it via sendgrid. However, once I change the API keys to environment variables it does not work anymore since it cannot get those environment variables from my pages directory. Do you have any ideas how to solve it?
3 Replies
Any help? What am I missing with regards to environmental variables in functions
env
isn't a global, it refers to an parameter that is passed to the handlers (like onRequestPost
).
async function handleRequest({ request })
should become async function handleRequest({ request, env })
, async function validateToken(ip, token)
should become async function validateToken(ip, token, env)
and then it will work.
https://developers.cloudflare.com/pages/platform/functions/api-reference/#eventcontextThanks I managed to get turnstile API to work with env, but not the sendgrid API