Allow setting a prefix for Livewire's update and asset urls

This commit is contained in:
Marcus Moore 2024-07-11 12:43:29 -07:00
parent 5132aa0254
commit 9dd3827222
No known key found for this signature in database
4 changed files with 52 additions and 1 deletions

View file

@ -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

View file

@ -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);
});
}
}

View file

@ -311,8 +311,9 @@ return [
App\Providers\ValidationServiceProvider::class,
/*
* Custom service provider
* Custom Service Providers...
*/
App\Providers\LivewireServiceProvider::class,
App\Providers\MacroServiceProvider::class,
App\Providers\SamlServiceProvider::class,

View file

@ -157,4 +157,21 @@ return [
*/
'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),
];