Skip to content

Commit d59c38e

Browse files
committed
Fix a fallback route issue causing API calls to return unauth responses and not 404s
The fallback handler isn't scoped to a specific group, so the way this was setup caused requests to non-existent API routes to actually try and return the base view for Vue. This caused a mess of issues because that view is behind the middleware that expect sessions to be set, thus leading to very confusing authentication errors rather than a 404 response.
1 parent 743ae04 commit d59c38e

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

app/Providers/RouteServiceProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ class RouteServiceProvider extends ServiceProvider
2222
public function map()
2323
{
2424
Route::middleware(['web', 'auth', 'csrf'])
25-
->namespace($this->namespace . '\Base')
26-
->group(base_path('routes/base.php'));
25+
->namespace($this->namespace . '\Base')
26+
->group(base_path('routes/base.php'));
2727

2828
Route::middleware(['web', 'auth', 'admin', 'csrf'])->prefix('/admin')
29-
->namespace($this->namespace . '\Admin')
30-
->group(base_path('routes/admin.php'));
29+
->namespace($this->namespace . '\Admin')
30+
->group(base_path('routes/admin.php'));
3131

3232
Route::middleware(['web', 'csrf'])->prefix('/auth')
33-
->namespace($this->namespace . '\Auth')
34-
->group(base_path('routes/auth.php'));
33+
->namespace($this->namespace . '\Auth')
34+
->group(base_path('routes/auth.php'));
3535

3636
Route::middleware(['web', 'csrf', 'auth', 'server', 'subuser.auth', 'node.maintenance'])
3737
->prefix('/api/server/{server}')
@@ -51,7 +51,7 @@ public function map()
5151
->group(base_path('routes/api-remote.php'));
5252

5353
Route::middleware(['web', 'daemon-old'])->prefix('/daemon')
54-
->namespace($this->namespace . '\Daemon')
55-
->group(base_path('routes/daemon.php'));
54+
->namespace($this->namespace . '\Daemon')
55+
->group(base_path('routes/daemon.php'));
5656
}
5757
}

routes/base.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<?php
22

3-
Route::get('/', 'IndexController@index')->name('index');
3+
Route::get('/', 'IndexController@index')->name('index')->fallback();
44
Route::get('/account', 'IndexController@index')->name('account');
55

6-
/*
7-
|--------------------------------------------------------------------------
8-
| Account Controller Routes
9-
|--------------------------------------------------------------------------
10-
|
11-
| Endpoint: /account
12-
|
13-
*/
14-
156
/*
167
|--------------------------------------------------------------------------
178
| Account API Controller Routes
@@ -23,9 +14,7 @@
2314
Route::group(['prefix' => 'account/api'], function () {
2415
Route::get('/', 'ClientApiController@index')->name('account.api');
2516
Route::get('/new', 'ClientApiController@create')->name('account.api.new');
26-
2717
Route::post('/new', 'ClientApiController@store');
28-
2918
Route::delete('/revoke/{identifier}', 'ClientApiController@delete')->name('account.api.revoke');
3019
});
3120

@@ -43,5 +32,5 @@
4332
Route::post('/totp/disable', 'SecurityController@delete')->name('account.two_factor.disable');
4433
});
4534

46-
// Catch any other combinations of routes and pass them off to the Vuejs component.
47-
Route::fallback('IndexController@index');
35+
Route::get('/{vue}', 'IndexController@index')
36+
->where('vue', '^(?!(\/)?(api|admin|daemon)).+');

0 commit comments

Comments
 (0)