We often call a server connect function from a different server connect call, by using the API Action. This works well, and allows us to reuse a complex database query and checks etc. However I’m wondering if there is a better way to do this rather than using the API Action?
The only real problem we have with this approach is it doesn’t seem possible to use localhost in the API call - we have to use either an IP address, or a FQDN. Using localhost throws a security error (even though there is no security on the server connect call to retrieve this data).
Using a fixed address has been ok for testing, and has worked fine over the past few months as we’ve just been running on a development system, however as we move to a production server, having a fixed address doesn’t work as we need to refer to different systems in each case.
It would be fine if we can use localhost, but better if there was a more ‘integrated’ way to call one server connect method from within another and I’d welcome any thoughts others have on achieving this goal.
Currently I’m running in a local Docker environment - I’d like to find a way to make these calls no-matter where the system is deployed - local or otherwise.
SERVER_ADDR works. I’m not sure why localhost or the HTTP_HOST fail - maybe it’s an issue with dns lookup that’s preventing this working. Anyway, many thanks for pointing me in the right direction here.
Unfortunately I’m still plagued with this issue as when we swap to the production server, different variables work - a different set than when we run locally . This ultimately means we have to keep swapping the API calls when we deploy to different servers which is far from ideal, and very error prone.
@George is there a recommended way to call one Server Connect API from within another? It feels like there should be to avoid duplicating complex queries etc, and I feel I’m probably missing something obvious.
It gives me a 404 - URI not found on the server. If I change to IP address, or a string URI, it works on the production server, but that’s not portable to the Docker container. I can use SERVER_ADDR on the Docker container, but not on the production system… It just feels like there should be a nice way in Wappler to make a SC call internally?
Thanks @mebeingken on my production system that works - I’ve not tested this in my Docker instance as I want to avoid swapping targets too often due to the bug with database connections, but if you’ve tested this then it looks like it could be a good workaround.
It still feels like this is something Wappler should do directly - ie be able to reference one SC call from another, rather than going via a separate API call. @George what do you think?
This can be done by using routes… choose server connect route then the server action you want to do… save and copy the url into the api url field on the server side. This is what worked for us.