Using Environment Variables for Workers API URLs
We have API Workers and WebSocket Worker for each of our environments (dev, test, prod).
CI/CD for Workers and Pages with GitHub almost* works great.
Because of the limitation of not being able to define different environment variables on different preview deployments and wanting custom domains for each, we have separate compute Pages configured for each env.
*The React webapp on Pages needs CF environment variables for its corresponding Workers API URLs.
Our thought is to use Pages Variables and Secrets and access them through Functions. This just seems overly complicated, and an extra set step every time it must access a Worker.
We’ve looked at the option of deploying the app as Worker instead of using Pages, and didn’t love it.
Is this really the ideal or most straight forward configuration to solve this? Or is there a better solution/configuration?
1 Reply
In the end we abandon Pages Variables and reverted to VITE. A much simpler, more generic config. Bonus tip: use t3-oss/env-core for React TS projects.