My Laravel App runs in sail on port 8000. I build a simple api route, that I can successfully call using postman: POST http://localhost:8000/api/auth/token:
Route::post('/api/auth/token', function () {
return [
'success' => true,
'auth_token' => bin2hex(random_bytes(16)),
];
});
When I try to call the endpoint from the web routes, it is timing out:
Route::get('/auth', function () {
$client = new GuzzleHttpClient();
return json_deconde($client->post('http://localhost/api/auth/token')
->getBody()
->getContents());
});
I tried to following hosts
- http://localhost:8000
- http://127.0.0.1:8000
- http://localhost
- http://127.0.0.1
- http://172.30.0.1 (what is the gateway if the sail container)
- http://192.168.168.10 (what is the network ip of the host)
Inside of the sail container curl --request POST 'http://localhost/api/auth/token' is successfully working.