Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lando has trouble accessing a URL from a non-Lando app on my system

My company has software that runs within Docker on my system, but is not using Lando. This software is serving some data via the URL: http://local.relay.cool:8081/clicks-bff/api/ads/

I can hit this URL in an anonymous browser, cURL it from the terminal, and load it via Postman and it returns the expected data.

I'm running Lando with the Wordpress recipe and I'm developing a plugin. This plugin can hit external URLs and retrieve data, I've tried with several different ones just to confirm.

However when Lando attempts to hit the URL listed above I get a WP_Error:

object(WP_Error)#1269 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(58) "cURL error 28: Resolving timed out after 5514 milliseconds" } } ["error_data"]=> array(0) { } }

Here's the .lando.yaml config block:

name: my app name
recipe: wordpress
config:
  webroot: wordpress

Is there some configuration option that I'm missing to allow Lando access to another URL on my machine?

like image 890
commadelimited Avatar asked Jul 16 '20 22:07

commadelimited


1 Answers

From your question, it sounds like the URL you're trying to access is running on a non-Lando docker container on your machine.

This means routing from your Lando instance to the service will be a bit different that usual. You should be able to accomplish this the same way you would access localhost endpoints. As explained in this Lando issue on GitHub, you must use the $LANDO_HOST_IP environment variable to route to local services.

Since your containers are all running inside of a light hyper-v instance you'll need to know the hostname or IP of the host machine. Generally we set $LANDO_HOST_IP to your computer . . .

So try something like this (assuming you're using PHP's curl):

curl_init('http://' . $_ENV["LANDO_HOST_IP"] . ':8081/clicks-bff/api/ads/');
like image 159
Nikolas Stevenson-Molnar Avatar answered Oct 17 '22 07:10

Nikolas Stevenson-Molnar