Support custom Plausible script path
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
dependabot-auto-merge / dependabot (pull_request_target) Skipped
Fix PHP code style issues / php-code-styling (push) Successful in 6s
PHPStan / phpstan (push) Successful in 2m32s
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 34s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 2s
Add a PLAUSIBLE_SCRIPT config option so site-specific scripts (js/pa-XXXXX.js) and legacy script extensions can be proxied. The script is still served locally from /js/script.js and the cache key is derived from the script URL so changing the script takes effect immediately. Closes #14
This commit is contained in:
4 files changed
+94
-27
No files matched your search
@@ -12,18 +12,14 @@ class PlausibleScriptProxyController
|
||||
{
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$url = rtrim((string) config('plausible-proxy.domain'), '/')
|
||||
.'/'.ltrim((string) config('plausible-proxy.script', 'js/script.js'), '/');
|
||||
|
||||
try {
|
||||
$script = Cache::remember(
|
||||
key: 'plausible_script_js',
|
||||
key: 'plausible_script_js:'.md5($url),
|
||||
ttl: now()->addHours(6),
|
||||
callback: function () {
|
||||
$plausibleDomain = config('plausible-proxy.domain');
|
||||
|
||||
return Http::timeout(5)
|
||||
->get("{$plausibleDomain}/js/script.js")
|
||||
->throw()
|
||||
->body();
|
||||
}
|
||||
callback: fn () => Http::timeout(5)->get($url)->throw()->body(),
|
||||
);
|
||||
} catch (RequestException $e) {
|
||||
Log::error('Failed to fetch Plausible script: '.$e->getMessage());
|
||||
|
||||
Reference in new issue
Block a user