Skip to content

Commit

Permalink
Fix manifest path when not accessible from URL (docker) (#3090)
Browse files Browse the repository at this point in the history
* Fix manifest path when not accessible from URL (docker)

* First check manifest absolute url else take relative path

* Fix url path
  • Loading branch information
lopes-vincent committed Mar 20, 2023
1 parent 79c2e57 commit 12d4118
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion local/modules/TheliaSmarty/Template/Plugins/Assets.php
Expand Up @@ -91,7 +91,11 @@ public function renderSvg($params, \Smarty_Internal_Template $template)
return false;
}

$svg = file_get_contents($path);
try {
$svg = file_get_contents($path);
} catch (\ErrorException $exception) {
$svg = file_get_contents(THELIA_WEB_DIR.$path);
}

$matches = [];
preg_match('/<svg.*?>/', $svg, $matches);
Expand Down
11 changes: 8 additions & 3 deletions local/modules/TheliaSmarty/Template/Plugins/Encore.php
Expand Up @@ -93,15 +93,20 @@ public function functionModuleAsset($args)

public function getWebpackManifestFile($args): string
{
$urlTool = URL::getInstance();

$file = $args['file'];
if (!$file) {
return '';
}

if (isset($this->packages['manifest'])) {
return $urlTool->absoluteUrl($this->packages['manifest']->geturl($file));
// Take absolute url if available else take relative path
$manifestPath = URL::getInstance()->absoluteUrl($this->packages['manifest']->geturl($file));
$fileHeaders = @get_headers($manifestPath);
if (!$fileHeaders || (int) substr($fileHeaders[0], 9, 3) >= 400) {
$manifestPath = $this->packages['manifest']->geturl($file);
}

return $manifestPath;
}

return '';
Expand Down

0 comments on commit 12d4118

Please sign in to comment.