I’m trying to make an api request from another backend (written in Node.js) to my Kirby API, but everything I try just results in ECONNREFUSED. What am I doing wrong?
const res = await fetch(`${apiUrl}/auth`, {
headers: {
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
'Content-Type': 'application/json'
}
})
I’ve tried HTTP and HTTPS, I’ve tried different endpoints, all of them give me the same result.
By contrast, fetching the same URL directly with my browser provides me with a JSON response saying that I’m unauthorized (expected).
Why doesn’t it work when making the request programmatically?
I have this in my config.php, although I’d like to remove that allowInsecure if I can :
'api' => [
'basicAuth' => true,
'allowInsecure' => true,
],
Any thoughts on how to troubleshoot this?
New to Kirby so excuse me if this is a newbie question.
Here is the specific error I get: FetchError: request to http://localhost:8000/api/auth failed, reason: connect ECONNREFUSED 127.0.0.1:8000
Apparently, the solution was to start Kirby using
php -S 0.0.0.0:8000
instead of usingphp -S localhost:8000
, and then reaching the API viahttp://0.0.0.0:8000/api
instead ofhttp://localhost:8000/api
.