Skip to content

Allow static cache warm to hit a custom URL #1383

@CapitaineToinon

Description

@CapitaineToinon

Hey !

I've been trying to use static caching on my dockerized statamic app and it seems like the current implementation always tries to hit localhost, meaning it's impossible to warm up the cache. It is worth noting that the caching works fine otherwise, hitting an uncached page will correctly cache the page for the next time.

When looking at the code for static:warm it seems that the entries always return absolute urls, meaning they all start with a slash and hit localhost.

https://github.com/statamic/cms/blob/c1f3f33b0b7820b0fa37656a86c40b77e29c38fa/src/Console/Commands/StaticWarm.php#L267-L289

However the Client used, which is just a GuzzleHttp\Client could accept a base_uri option to allow hitting a different host.

https://github.com/statamic/cms/blob/c1f3f33b0b7820b0fa37656a86c40b77e29c38fa/src/Console/Commands/StaticWarm.php#L86

https://docs.guzzlephp.org/en/stable/quickstart.html#creating-a-client

In my case, I have two docker services, one php running php-fpm on port 9000 and an nginx service listening to port 80. The static:warm command runs on the php service and therefore get a 404 when trying to warm the cache.

laravel-1      |   /eldenring/pegasus-glitch  cURL error 7: Failed to connect to localhost port 80 after 0 ms: Could not connect to server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost/eldenring/pegasus-glitch
laravel-1      |   /eldenring/practice-tool  cURL error 7: Failed to connect to localhost port 80 after 0 ms: Could not connect to server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost/eldenring/practice-tool

In my case, I would need the command to hit http://web/eldenring instead of just /eldenring.

If we just add a base uri option to the warm command, the change should be pretty simple. If you guys think that would be an good addition, I can make a PR for it.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions