Skip to content

A free open source IT asset/license management system

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

Marcus Moore9dd382722266
diff --git a/.env.example b/.env.example
index c92dc22b71..5c0a0b8abc 100644
--- a/.env.example
+++ b/.env.example
@@ -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
diff --git a/app/Providers/LivewireServiceProvider.php b/app/Providers/LivewireServiceProvider.php
new file mode 100644
index 0000000000..9fd0fd561f
--- /dev/null
+++ b/app/Providers/LivewireServiceProvider.php
@@ -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);
+ });
+ }
+}
diff --git a/config/app.php b/config/app.php
index 61c06177f3..44f2d26555 100755
--- a/config/app.php
+++ b/config/app.php
@@ -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,
diff --git a/config/livewire.php b/config/livewire.php
index 8cc482183b..d9db384bd6 100644
--- a/config/livewire.php
+++ b/config/livewire.php
@@ -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),
];