i’m trying to use Remote::get() and fetch the kirby apis of the current website i’m working on.
i use valet to run my local php env. valet uses dnsmasq. i can access the custom domain perfectly either through the browser as well as pinging it form the terminal (which returns 127.0.0.1).
when i do the Remote::get() call i get a No Message response. if i use a full url (eg my custom valet url) I get a dns problem saying it could not resolve the domain. if i use http://127.0.0.1 i also get a No message exception (kirby/src/Http/Remote.php 228).
$email and $password are added manually for now but i’ll query them through a $kirby callback.
config.php settings
'api' => [
'basicAuth' => true
]
NB I am able to fetch the kirby apis from javascript, but i am in a situation where for some views of the app i am doing 4-5 calls and it slows down a lot the rendering. therefore i was thinking of setting routes for each view and pre-loading the json endpoint with the necessary data for the js fetch call upfront.
any hint appreciated! i might be mis-configuring the kirby plugin maybe.
@jimbobrjames could you make an example with fetch() inside a plugin?
this is my first attempt, but docs are lacking examples. can fetch() take an array of arguments like new Remote() does? can i do ['u', 'username:password'] like in curl?
I’ve never tried it im afraid, and im not the best with this kind of thing, but from poking around, i think you need to go through new:Remote which runs it through fetch.
Does it work if you turn off Valet SSL and do it just with http? Im thinking the request via the plugin knows the certificate isnt “real”. However the default seems to be false i think for checking it, so I’m out of ideas.
thanks again. using an http version did not help, same error. i guess i’ll move on the website to my vps and work from there, developing the js app locally.
Ok i think im on to something, i believe you need your local machine to be first thing the machine tries for DNS lookups before moving on to remote DNS servers… remember to keep whatever is already set for DNS, just make sure localhost is at the top.
i tried both the 127.0.0.1 setting as well as uninstalling openssl to match the same curl version with php but no luck
i’m a bit confused now as i began using valet rather the php -S because of kirby 3 new architecture. i have no desire to run mamp. i guess it’s an edge case for now so i’ll simply upload the kirby server on my vps and see if that resolves this problem.
to be honest, after i added the 127.0.0.1 the first time, the http call went well! then i updated the rest of the code to get the data in the frontend and i realized my internet went away, so i added a second dns entry after 127… and from there on it did not work. i tried to take out all dns entries and put back only 127…, i reverted back my code etc.
not sure why that first time worked, unless i hallucinated lol.
Just for anyone else who wants to test modifying the /etc/hosts file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Adding this last line for an example domain 315.test solved it for me
127.0.0.1 325.test