Dynamic options via JSON API for select field

I build an internal API to filter some structure fields for some select fields in the panel.

The dynamic option of the select field (
https://getkirby.com/docs/cheatsheet/panel-fields/select) need an absolut url which is different on my local machine and on the production environment.

So, is there an way to request an internal api with /api/method? Any other ideas to solve this problem?

Thanks in advance

1 Like

You have to pass an absolute URL, see this post, also for an alternative.

Thank you, @texnixe! Unfortunately, custom select fields are not really an option in our scenario. We’ll now use the production url on localhost. Maybe I’ll also use some redirects via .htaccess.

Just came across this answer:

@jensfranke Another idea just came to me: You could use some DNS tricks to override the actual IP of the production URL when on a local network.

On *nix systems you’d add local hosts in /etc/hosts. You may have seen this before when working with local domains, i.e. mycomputer.local or my-app.dev or similar.    dev-api-url.example.com

# Override the IP for google.com
# Requests for google.com will not work, as the below IP
# doesn't serve google's site.     google.com

# Note that you'll need a second entry for www
# and any additional subdomains     google.com     www.google.com     somewhere-else.google.com

# You cannot use wildcards or globs in /etc/hosts
# Doesn't work:    *.google.com

Now when developing locally, this setting will override the IP address your machine looks up to use the API URL, where as other machines or networks without this setting will use the default IP, which usually comes from some DNS provider.

Then you wouldn’t have to worry about storing this value in Kirby; defer it to the network.

Surely this approach has some caveats, but it’s worth throwing in as an option.