How to build an app with the ability to switch between environments

Hi there.

Imagine we have an app that is tested on a test version of the backend, and there’s a prod version of the backend that we need to test on before releasing as well.

As of now, I have all my scripts that send requests using Fetch API in a separate folder. I also have a config file where there’s a variable that says if it’s dev env or prod. To get a version for each backend, I have to build the app twice with different values of the variable which is not convenient for me and QA at all.

I’m wondering if there’s a built-in solution or a pattern that people use to get switching available right in the standalone app for testing like there’s a button that could be pressed to toggle the env type, and then all the requests are forwarded to the latter backend. The problem is that my config file and request files are not aware of the context.

Are there any?
Thanks in advance.