React CORS error in netlify

I directly texted my api-key into the fetch call and it worked. I changed it to .env format again and it is gone now :grinning_face_with_smiling_eyes:

Hi, @serdargokhan. The environment variables only exist during the site build. Once the site build ends those environment variables no longer exist. If you reference them in client site javascript they will be undefined and therefore empty.

The workaround for this is to often to hard code them into javascript itself if this is an API key which can be shared publicly. However, if these are API keys that should remain private, there is a different workflow described in this support guide:

Note, I don’t know anything about the API the app is consuming, but if this is related to financial services my best guess is that you will not want to expose that key. publicly

I think I will use netlify serverless functions. Thank you for all of your answers. Especially @coelmay. I am appreciate for your helps. I fixed CORS error :slight_smile:

1 Like