Relative url with drush context (CDN warmer)

Created on 22 August 2024, 3 months ago

Problem/Motivation

When you use relative URLs in the CDN Warmer and attempt to warm them with the following commands:

vendor/bin/drush warmer:enqueue cdn
vendor/bin/drush queue-run warmer

If your server does not have your website domain set in its environment variables, you'll get an absolute URL like this: https://default/my/relative/url.
This URL is returned by the resolveUri function, which uses Url::fromUri and Url::fromUserInput to convert relative URLs to absolute ones.

In my case, we cannot or do not want to set an environment variable on our server because it hosts multiple websites.

This issue does not occur in a website context (if you warm your CDN from the back office interfaces). In this scenario, the Url class can retrieve the actual website scheme and host because it operates within an HTTP request context.

For now, I’ve just split my configurations and directly set the absolute URLs in the CDN configuration, since I only have around 20 URLs to warm.

Proposed resolution

Should this module have the actual website base url in its configuration to avoid this problem in a drush context ?
We could simply change the resolveUri function to concatenate relative urls with the base url store in the module configuraiton.

Let me now what you think about this issue and if there is another way to deal with it.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France t.maquin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024