Skip to content

Commit

Permalink
Allow setting a prefix for Livewire's update and asset urls
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmoore committed Jul 11, 2024
1 parent 5132aa0 commit 9dd3827
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ REPORT_TIME_LIMIT=12000
REQUIRE_SAML=false
API_THROTTLE_PER_MINUTE=120
CSV_ESCAPE_FORMULAS=true
LIVEWIRE_URL_PREFIX=null

# --------------------------------------------
# OPTIONAL: HASHING
Expand Down
32 changes: 32 additions & 0 deletions app/Providers/LivewireServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;

class LivewireServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/' . config('livewire.url_prefix') . '/livewire/update', $handle);
});

Livewire::setScriptRoute(function ($handle) {
return Route::get('/' . config('livewire.url_prefix') . '/livewire/livewire.js', $handle);
});
}
}
3 changes: 2 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@
App\Providers\ValidationServiceProvider::class,

/*
* Custom service provider
* Custom Service Providers...
*/
App\Providers\LivewireServiceProvider::class,
App\Providers\MacroServiceProvider::class,
App\Providers\SamlServiceProvider::class,

Expand Down
17 changes: 17 additions & 0 deletions config/livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,21 @@
*/

'pagination_theme' => 'tailwind',

/*
|---------------------------------------------------------------------------
| URL Prefix
|---------------------------------------------------------------------------
|
| By default, Livewire sends network requests to {app.com}/livewire/update
| while javascript assets are served via {app.com}/livewire/livewire.js
| If you need to adjust the prefix of those urls you can do it below.
|
| Defining a prefix will result in the following url
| {app.com}/{prefix}/livewire/{update|livewire.js}
| Note: do not include the leading or trailing /
|
*/

'url_prefix' => env('LIVEWIRE_URL_PREFIX', null),
];

0 comments on commit 9dd3827

Please sign in to comment.