Skip to content

Conversation

@CapitaineToinon
Copy link
Contributor

@CapitaineToinon CapitaineToinon commented Nov 24, 2025

As stated in #13145, this PR fixes the StaticWarm command to work behind a reverse proxy by setting the Guzzle client to hit config('app.url') by default. This means that if laravel isn't exposed to the internet but instead is reverse proxied by nginx that passes back the requests to php-fpm, this will use the config('app.url') to hit nginx instead of localhost as it does currently.

This PR also adds a simple base_uri option to the command to override that base_uri. This can be useful if you wish laravel hits the other nginx docker service, for example by setting --base_uri=http://nginx for example.

Fixes #13145

@CapitaineToinon
Copy link
Contributor Author

I wanted to add a unit test but turns out the test it_sets_custom_headers_on_requests that I tried to base my code on is also broken. It tries to mock Guzzle Client but that client is never injected, instead called directly in the code with new, making the mock useless.

@CapitaineToinon
Copy link
Contributor Author

So the problem is that Guzzle Client is never injected anywhere by laravel but instead created using the new keyword. However, the it_sets_custom_headers_on_requests test tries to mock the Client using this->app->bind. The mock client is then never used but since the way the send method is tested is only shouldRecieve('send') but not shouldRecieve('send')->twice() (since the setUp creates two pages), then it succeeds even though it's never called.

By the way, when using a Guzzle Pool, the pool will call sendAsync and not send. Of course replacing by sendAsync doesn't fix the core issue.

I tried fixing this but since it seems like the code is using Guzzle Requests all over the place, I can't simple replace Guzzle by Laravel's Http Client. I think we would need a Client factory and then that factory could be mocked instead.

Let me know how you prefer to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

static:warm command doesn't work if laravel is behind a reverse proxy

1 participant