Skip to content

Commit

Permalink
Allow to set app URL (separated from asset URL)
Browse files Browse the repository at this point in the history
lucasromanojf committed Nov 29, 2019
1 parent ad11979 commit 71a77f8
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ SCRATCH.md
COMMIT_MSG.aim.txt
composer.lock
.phpunit.result.cache
.idea
26 changes: 21 additions & 5 deletions config/livewire.php
Original file line number Diff line number Diff line change
@@ -36,12 +36,28 @@
| your app's domain root is not the correct path. By default, Livewire
| will load its JavaScript assets from the app's "relative root".
|
| Examples: "/assets", "myurl.com/app"
| Examples: "/assets", "myurl.com/app", "env('ASSET_URL', null)"
|
*/

'asset_url' => null,

/*
|--------------------------------------------------------------------------
| Livewire App URL
|--------------------------------------------------------------------------
|
| This value sets Livewire endpoint's base URL, for cases where
| your app's domain root is not the same as the assets URL above (e.g.: Laravel
| Vapor, where assets URL points to Cloudfront but your app is under your own domain).
| By default, Livewire will consider the asset URL above as the app URL.
|
| Examples: "/admin", "myurl.com/app", "env('APP_URL', null)"
|
*/

'app_url' => null,

/*
|--------------------------------------------------------------------------
| Livewire Endpoint Middleware Group
@@ -54,21 +70,21 @@
*/

'middleware_group' => 'web',

/*
|--------------------------------------------------------------------------
| Manifest File Path
|--------------------------------------------------------------------------
|
| This value sets the path to Livewire manifest file path.
| The default should work for most cases (which is
| "<app_root>/bootstrap/cache/livewire-components.php)", but for specific
| The default should work for most cases (which is
| "<app_root>/bootstrap/cache/livewire-components.php)", but for specific
| cases like when hosting on Laravel Vapor, it could be set to a different value.
|
| Example: For Laravel Vapor, it would be "/tmp/storage/bootstrap/cache/livewire-components.php"
|
*/

'manifest_path' => null,

];
7 changes: 4 additions & 3 deletions src/LivewireManager.php
Original file line number Diff line number Diff line change
@@ -164,22 +164,23 @@ protected function javaScriptAssets($jsFileName, $options)
{
$jsonEncodedOptions = $options ? json_encode($options) : '';

$appUrl = config('livewire.asset_url', rtrim($options['asset_url'] ?? '', '/'));
$assetUrl = config('livewire.asset_url', rtrim($options['asset_url'] ?? '', '/'));
$appUrl = config('livewire.app_url', $assetUrl);

$csrf = csrf_token();

$manifest = json_decode(file_get_contents(__DIR__.'/../dist/mix-manifest.json'), true);
$versionedFileName = $manifest[$jsFileName];

// Default to dynamic `livewire.js` (served by a Laravel route).
$fullAssetPath = "{$appUrl}/livewire{$versionedFileName}";
$fullAssetPath = "{$assetUrl}/livewire{$versionedFileName}";
$assetWarning = null;

// Use static assets if they have been published
if (file_exists(public_path('vendor/livewire'))) {
$publishedManifest = json_decode(file_get_contents(public_path('vendor/livewire/mix-manifest.json')), true);
$versionedFileName = $publishedManifest[$jsFileName];
$fullAssetPath = "{$appUrl}/vendor/livewire{$versionedFileName}";
$fullAssetPath = "{$assetUrl}/vendor/livewire{$versionedFileName}";

if ($manifest !== $publishedManifest) {
$assetWarning = <<<'HTML'

0 comments on commit 71a77f8

Please sign in to comment.