From 20cca2650fe67177815f4e874766c50efcc0f6d6 Mon Sep 17 00:00:00 2001 From: Albert Haff Date: Fri, 12 Nov 2021 14:55:02 +0100 Subject: [PATCH 1/2] Add flexible route configuration --- config/vapor-ui.php | 26 +++++++++++++++++++++++ resources/js/app.js | 2 +- resources/js/components/Search.vue | 2 +- resources/js/components/SearchDetails.vue | 11 ++++++---- resources/js/screens/jobs/metrics.vue | 2 +- resources/js/screens/jobs/show.vue | 2 +- resources/views/layout.blade.php | 1 + routes/web.php | 3 +-- src/Http/Controllers/HomeController.php | 1 + src/VaporUiServiceProvider.php | 17 ++++++++++++++- 10 files changed, 56 insertions(+), 11 deletions(-) diff --git a/config/vapor-ui.php b/config/vapor-ui.php index fc3926b..e0e76b7 100644 --- a/config/vapor-ui.php +++ b/config/vapor-ui.php @@ -24,6 +24,32 @@ EnsureUpToDateAssets::class, ], + /* + |-------------------------------------------------------------------------- + | Vapor UI Domain + |-------------------------------------------------------------------------- + | + | This is the subdomain where Vapor UI will be accessible from. If this + | setting is null, Vapor UI will reside under the same domain as the + | application. Otherwise, this value will serve as the subdomain. + | + */ + + 'domain' => env('VAPOR_UI_DOMAIN', null), + + /* + |-------------------------------------------------------------------------- + | Vapor UI Path + |-------------------------------------------------------------------------- + | + | This is the URI path where Vapor UI will be accessible from. Feel free + | to change this path to anything you like. Note that the URI will not + | affect the paths of its internal API that aren't exposed to users. + | + */ + + 'path' => env('VAPOR_UI_PATH', 'vapor-ui'), + /* |-------------------------------------------------------------------------- | Vapor UI Queues diff --git a/resources/js/app.js b/resources/js/app.js index 2fb3010..332e9c7 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -19,7 +19,7 @@ moment.tz.setDefault('utc'); const router = new VueRouter({ routes: Routes, mode: 'history', - base: '/vapor-ui', + base: '/' + window.VaporUi.path, }); router.beforeEach((to, from, next) => { diff --git a/resources/js/components/Search.vue b/resources/js/components/Search.vue index 890069d..9d88aff 100644 --- a/resources/js/components/Search.vue +++ b/resources/js/components/Search.vue @@ -342,7 +342,7 @@ export default { this.searching = true; return axios - .get(`/vapor-ui/api/${this.$route.meta.resource}/${this.group}`, { params }) + .get(`/${window.VaporUi.path}/api/${this.$route.meta.resource}/${this.group}`, { params }) .catch(({ response }) => { this.searching = false; this.troubleshooting = true; diff --git a/resources/js/components/SearchDetails.vue b/resources/js/components/SearchDetails.vue index 53a743a..7669104 100644 --- a/resources/js/components/SearchDetails.vue +++ b/resources/js/components/SearchDetails.vue @@ -114,10 +114,13 @@ export default { */ mounted() { axios - .get(`/vapor-ui/api/${this.$route.meta.resource}/${this.$route.params.group}/${this.$route.params.id}`, { - params: this.$route.query, - validateStatus: false, - }) + .get( + `/${window.VaporUi.path}/api/${this.$route.meta.resource}/${this.$route.params.group}/${this.$route.params.id}`, + { + params: this.$route.query, + validateStatus: false, + } + ) .then(({ data }) => { this.ready = true; this.entry = data; diff --git a/resources/js/screens/jobs/metrics.vue b/resources/js/screens/jobs/metrics.vue index ebcea13..6d0d324 100644 --- a/resources/js/screens/jobs/metrics.vue +++ b/resources/js/screens/jobs/metrics.vue @@ -198,7 +198,7 @@ export default { this.$router.push({ query: Object.assign({}, this.$route.query, this.filters) }).catch(() => {}); return axios - .get('/vapor-ui/api/jobs/metrics', { + .get(`/${window.VaporUi.path}/api/jobs/metrics`, { params: this.filters, }) .then(({ data }) => { diff --git a/resources/js/screens/jobs/show.vue b/resources/js/screens/jobs/show.vue index 42ef3d4..1d2df20 100644 --- a/resources/js/screens/jobs/show.vue +++ b/resources/js/screens/jobs/show.vue @@ -218,7 +218,7 @@ export default { 1000 ); - axios.post(`/vapor-ui/api/jobs/failed/${action}/${entry.id}`).then(then); + axios.post(`/${window.VaporUi.path}/api/jobs/failed/${action}/${entry.id}`).then(then); }, }, }; diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index 2c2c49f..1649420 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -118,6 +118,7 @@ class="group flex items-center px-2 py-2 text-sm leading-5 font-medium text-gray diff --git a/routes/web.php b/routes/web.php index 05e0f07..8d6561d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,8 +6,7 @@ use Laravel\VaporUi\Http\Controllers\JobMetricController; use Laravel\VaporUi\Http\Controllers\LogController; -Route::prefix('vapor-ui') - ->middleware('vapor-ui') +Route::middleware('vapor-ui') ->group(function () { Route::get('/api/logs/{group}', [LogController::class, 'index']); Route::get('/api/logs/{group}/{id}', [LogController::class, 'show']); diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index 7058c58..4166c98 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -15,6 +15,7 @@ class HomeController public function __invoke() { return view('vapor-ui::layout', [ + 'path' => config('vapor-ui.path', 'vapor-ui'), 'queues' => Cloud::queues(), ]); } diff --git a/src/VaporUiServiceProvider.php b/src/VaporUiServiceProvider.php index f028a78..510ddbf 100644 --- a/src/VaporUiServiceProvider.php +++ b/src/VaporUiServiceProvider.php @@ -23,7 +23,7 @@ public function boot() { Route::middlewareGroup('vapor-ui', config('vapor-ui.middleware', [])); - $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); + $this->registerRoutes(); $this->loadViewsFrom(__DIR__.'/../resources/views', 'vapor-ui'); if ($this->app->runningInConsole()) { @@ -87,4 +87,19 @@ public function registerClients() }); }); } + + /** + * Register the Vapor UI routes. + * + * @return void + */ + protected function registerRoutes() + { + Route::group([ + 'domain' => config('vapor-ui.domain', null), + 'prefix' => config('vapor-ui.path', 'vapor-ui'), + ], function () { + $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); + }); + } } From cb88283ef9cdadd2d52f5194a215aeea231ae8b3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 15 Nov 2021 09:01:29 -0600 Subject: [PATCH 2/2] formatting --- config/vapor-ui.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/vapor-ui.php b/config/vapor-ui.php index e0e76b7..cb6797e 100644 --- a/config/vapor-ui.php +++ b/config/vapor-ui.php @@ -31,7 +31,7 @@ | | This is the subdomain where Vapor UI will be accessible from. If this | setting is null, Vapor UI will reside under the same domain as the - | application. Otherwise, this value will serve as the subdomain. + | application. Otherwise this value should serve as the subdomain. | */ @@ -43,8 +43,8 @@ |-------------------------------------------------------------------------- | | This is the URI path where Vapor UI will be accessible from. Feel free - | to change this path to anything you like. Note that the URI will not - | affect the paths of its internal API that aren't exposed to users. + | to change the path to anything you like. Note that the URI will not + | affect the paths of its internal API that isn't exposed to users. | */