App.request different url in dev and prod

Hi,

How can I use different urls with app.request in dev and prod?
For development I need “$f7.request.post('http://localhost:8080/…”, in production $f7.request.post('https://mydomain.xx/

Currently I do a search and replace but there must be a better way…
Is it possible to set a variable to different values in prod and dev?
I use F7 core.

If your url same as domain, you can use window.origin as the hostname.

or with variable

const hostname = window.origin == “http://localhost:8080” ? “http://localhost:8080” : “https://mydomain.xx

If you use Vite bundler then you can do it like so:

$f7.request.post(import.meta.env.PROD ?  'https://mydomain.xx' : 'http://localhost:8080')

You could use a global variable for the URL and just change the one variable before build. Reference the variable throughout your code instead of hard-coding the URL into each function.