Skip to content

Commit

Permalink
feat: If the devServer is running, the ViteService::fetch() metho…
Browse files Browse the repository at this point in the history
…d will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](#22))
  • Loading branch information
khalwat committed Jan 22, 2024
1 parent fc2ccb9 commit ed4c7d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/services/ViteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public function devServerRunning(): bool
*/
public function fetch(string $pathOrUrl, callable $callback = null)
{
// If the devServer is running, and this is a URL, swap in the devServerInternal URL
if ($this->devServerRunning()) {
if (!filter_var($pathOrUrl, FILTER_VALIDATE_URL) === false) {
$devServerInternalUrl = str_replace($this->devServerPublic, '', $pathOrUrl);
$devServerInternalUrl = FileHelper::createUrl($this->devServerInternal, $devServerInternalUrl);
// If we get a result from the $devServerInternalUrl, return it
if ($devServerInternalResult = FileHelper::fetch($devServerInternalUrl, $callback, $this->cacheKeySuffix)) {
return $devServerInternalResult;
}
}
}

return FileHelper::fetch($pathOrUrl, $callback, $this->cacheKeySuffix);
}

Expand Down

0 comments on commit ed4c7d0

Please sign in to comment.