Skip to content

Commit 65f27d4

Browse files
committed
Switch to more recent Laravel route definition methods
1 parent 62b178e commit 65f27d4

File tree

9 files changed

+296
-326
lines changed

9 files changed

+296
-326
lines changed

app/Http/Kernel.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Pterodactyl\Http;
44

5-
use Illuminate\Http\Middleware\TrustProxies;
65
use Pterodactyl\Models\ApiKey;
76
use Illuminate\Auth\Middleware\Authorize;
7+
use Illuminate\Http\Middleware\TrustProxies;
88
use Illuminate\Auth\Middleware\Authenticate;
99
use Pterodactyl\Http\Middleware\TrimStrings;
1010
use Illuminate\Session\Middleware\StartSession;
@@ -72,21 +72,18 @@ class Kernel extends HttpKernel
7272
IsValidJson::class,
7373
StartSession::class,
7474
AuthenticateSession::class,
75+
VerifyCsrfToken::class,
76+
],
77+
'application-api' => [
7578
ApiSubstituteBindings::class,
7679
'api..key:' . ApiKey::TYPE_APPLICATION,
7780
AuthenticateApplicationUser::class,
78-
VerifyCsrfToken::class,
7981
AuthenticateIPAccess::class,
8082
],
8183
'client-api' => [
82-
HandleStatelessRequest::class,
83-
IsValidJson::class,
84-
StartSession::class,
85-
AuthenticateSession::class,
8684
SubstituteClientApiBindings::class,
8785
'api..key:' . ApiKey::TYPE_ACCOUNT,
8886
AuthenticateIPAccess::class,
89-
VerifyCsrfToken::class,
9087
// This is perhaps a little backwards with the Client API, but logically you'd be unable
9188
// to create/get an API key without first enabling 2FA on the account, so I suppose in the
9289
// end it makes sense.

app/Providers/RouteServiceProvider.php

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010

1111
class RouteServiceProvider extends ServiceProvider
1212
{
13-
/**
14-
* This namespace is applied to the controller routes in your routes file.
15-
*
16-
* In addition, it is set as the URL generator's root namespace.
17-
*
18-
* @var string
19-
*/
20-
protected $namespace = 'Pterodactyl\Http\Controllers';
21-
2213
/**
2314
* Define your route model bindings, pattern filters, etc.
2415
*/
@@ -27,35 +18,23 @@ public function boot()
2718
$this->configureRateLimiting();
2819

2920
$this->routes(function () {
30-
Route::middleware(['web', 'auth', 'csrf'])
31-
->namespace("$this->namespace\\Base")
32-
->group(base_path('routes/base.php'));
33-
34-
Route::middleware(['web', 'auth', 'admin', 'csrf'])->prefix('/admin')
35-
->namespace("$this->namespace\\Admin")
36-
->group(base_path('routes/admin.php'));
37-
38-
Route::middleware(['web', 'csrf'])->prefix('/auth')
39-
->namespace("$this->namespace\\Auth")
40-
->group(base_path('routes/auth.php'));
41-
42-
Route::middleware(['web', 'csrf', 'auth', 'server', 'node.maintenance'])
43-
->prefix('/api/server/{server}')
44-
->namespace("$this->namespace\\Server")
45-
->group(base_path('routes/server.php'));
46-
47-
Route::middleware(['api', 'throttle:api.application'])
48-
->prefix('/api/application')
49-
->namespace("$this->namespace\\Api\\Application")
50-
->group(base_path('routes/api-application.php'));
51-
52-
Route::middleware(['client-api', 'throttle:api.client'])
53-
->prefix('/api/client')
54-
->namespace("$this->namespace\\Api\\Client")
55-
->group(base_path('routes/api-client.php'));
56-
57-
Route::middleware(['daemon'])->prefix('/api/remote')
58-
->namespace("$this->namespace\\Api\\Remote")
21+
Route::middleware(['web', 'csrf'])->group(function () {
22+
Route::middleware('auth')->group(base_path('routes/base.php'));
23+
Route::middleware('guest')->prefix('/auth')->group(base_path('routes/auth.php'));
24+
Route::middleware(['auth', 'admin'])->prefix('/admin')->group(base_path('routes/admin.php'));
25+
});
26+
27+
Route::middleware('api')->group(function () {
28+
Route::middleware(['application-api', 'throttle:api.application'])
29+
->prefix('/api/application')
30+
->group(base_path('routes/api-application.php'));
31+
32+
Route::middleware(['client-api', 'throttle:api.client'])
33+
->prefix('/api/client')
34+
->group(base_path('routes/api-client.php'));
35+
});
36+
37+
Route::middleware('daemon')->prefix('/api/remote')
5938
->group(base_path('routes/api-remote.php'));
6039
});
6140
}

routes/admin.php

Lines changed: 110 additions & 108 deletions
Large diffs are not rendered by default.

routes/api-application.php

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4+
use Pterodactyl\Http\Controllers\Api\Application;
45

56
/*
67
|--------------------------------------------------------------------------
@@ -12,14 +13,14 @@
1213
*/
1314

1415
Route::group(['prefix' => '/users'], function () {
15-
Route::get('/', 'Users\UserController@index')->name('api.application.users');
16-
Route::get('/{user}', 'Users\UserController@view')->name('api.application.users.view');
17-
Route::get('/external/{external_id}', 'Users\ExternalUserController@index')->name('api.application.users.external');
16+
Route::get('/', [Application\Users\UserController::class, 'index'])->name('api.application.users');
17+
Route::get('/{user}', [Application\Users\UserController::class, 'view'])->name('api.application.users.view');
18+
Route::get('/external/{external_id}', [Application\Users\ExternalUserController::class, 'index'])->name('api.application.users.external');
1819

19-
Route::post('/', 'Users\UserController@store');
20-
Route::patch('/{user}', 'Users\UserController@update');
20+
Route::post('/', [Application\Users\UserController::class, 'store']);
21+
Route::patch('/{user}', [Application\Users\UserController::class, 'update']);
2122

22-
Route::delete('/{user}', 'Users\UserController@delete');
23+
Route::delete('/{user}', [Application\Users\UserController::class, 'delete']);
2324
});
2425

2526
/*
@@ -31,20 +32,20 @@
3132
|
3233
*/
3334
Route::group(['prefix' => '/nodes'], function () {
34-
Route::get('/', 'Nodes\NodeController@index')->name('api.application.nodes');
35-
Route::get('/deployable', 'Nodes\NodeDeploymentController');
36-
Route::get('/{node}', 'Nodes\NodeController@view')->name('api.application.nodes.view');
37-
Route::get('/{node}/configuration', 'Nodes\NodeConfigurationController');
35+
Route::get('/', [Application\Nodes\NodeController::class, 'index'])->name('api.application.nodes');
36+
Route::get('/deployable', Application\Nodes\NodeDeploymentController::class);
37+
Route::get('/{node}', [Application\Nodes\NodeController::class, 'view'])->name('api.application.nodes.view');
38+
Route::get('/{node}/configuration', Application\Nodes\NodeConfigurationController::class);
3839

39-
Route::post('/', 'Nodes\NodeController@store');
40-
Route::patch('/{node}', 'Nodes\NodeController@update');
40+
Route::post('/', [Application\Nodes\NodeController::class, 'store']);
41+
Route::patch('/{node}', [Application\Nodes\NodeController::class, 'update']);
4142

42-
Route::delete('/{node}', 'Nodes\NodeController@delete');
43+
Route::delete('/{node}', [Application\Nodes\NodeController::class, 'delete']);
4344

4445
Route::group(['prefix' => '/{node}/allocations'], function () {
45-
Route::get('/', 'Nodes\AllocationController@index')->name('api.application.allocations');
46-
Route::post('/', 'Nodes\AllocationController@store');
47-
Route::delete('/{allocation}', 'Nodes\AllocationController@delete')->name('api.application.allocations.view');
46+
Route::get('/', [Application\Nodes\AllocationController::class, 'index'])->name('api.application.allocations');
47+
Route::post('/', [Application\Nodes\AllocationController::class, 'store']);
48+
Route::delete('/{allocation}', [Application\Nodes\AllocationController::class, 'delete'])->name('api.application.allocations.view');
4849
});
4950
});
5051

@@ -57,13 +58,13 @@
5758
|
5859
*/
5960
Route::group(['prefix' => '/locations'], function () {
60-
Route::get('/', 'Locations\LocationController@index')->name('api.applications.locations');
61-
Route::get('/{location}', 'Locations\LocationController@view')->name('api.application.locations.view');
61+
Route::get('/', [Application\Locations\LocationController::class, 'index'])->name('api.applications.locations');
62+
Route::get('/{location}', [Application\Locations\LocationController::class, 'view'])->name('api.application.locations.view');
6263

63-
Route::post('/', 'Locations\LocationController@store');
64-
Route::patch('/{location}', 'Locations\LocationController@update');
64+
Route::post('/', [Application\Locations\LocationController::class, 'store']);
65+
Route::patch('/{location}', [Application\Locations\LocationController::class, 'update']);
6566

66-
Route::delete('/{location}', 'Locations\LocationController@delete');
67+
Route::delete('/{location}', [Application\Locations\LocationController::class, 'delete']);
6768
});
6869

6970
/*
@@ -75,31 +76,31 @@
7576
|
7677
*/
7778
Route::group(['prefix' => '/servers'], function () {
78-
Route::get('/', 'Servers\ServerController@index')->name('api.application.servers');
79-
Route::get('/{server}', 'Servers\ServerController@view')->name('api.application.servers.view');
80-
Route::get('/external/{external_id}', 'Servers\ExternalServerController@index')->name('api.application.servers.external');
79+
Route::get('/', [Application\Servers\ServerController::class, 'index'])->name('api.application.servers');
80+
Route::get('/{server}', [Application\Servers\ServerController::class, 'view'])->name('api.application.servers.view');
81+
Route::get('/external/{external_id}', [Application\Servers\ExternalServerController::class, 'index'])->name('api.application.servers.external');
8182

82-
Route::patch('/{server}/details', 'Servers\ServerDetailsController@details')->name('api.application.servers.details');
83-
Route::patch('/{server}/build', 'Servers\ServerDetailsController@build')->name('api.application.servers.build');
84-
Route::patch('/{server}/startup', 'Servers\StartupController@index')->name('api.application.servers.startup');
83+
Route::patch('/{server}/details', [Application\Servers\ServerDetailsController::class, 'details'])->name('api.application.servers.details');
84+
Route::patch('/{server}/build', [Application\Servers\ServerDetailsController::class, 'build'])->name('api.application.servers.build');
85+
Route::patch('/{server}/startup', [Application\Servers\StartupController::class, 'index'])->name('api.application.servers.startup');
8586

86-
Route::post('/', 'Servers\ServerController@store');
87-
Route::post('/{server}/suspend', 'Servers\ServerManagementController@suspend')->name('api.application.servers.suspend');
88-
Route::post('/{server}/unsuspend', 'Servers\ServerManagementController@unsuspend')->name('api.application.servers.unsuspend');
89-
Route::post('/{server}/reinstall', 'Servers\ServerManagementController@reinstall')->name('api.application.servers.reinstall');
87+
Route::post('/', [Application\Servers\ServerController::class, 'store']);
88+
Route::post('/{server}/suspend', [Application\Servers\ServerManagementController::class, 'suspend'])->name('api.application.servers.suspend');
89+
Route::post('/{server}/unsuspend', [Application\Servers\ServerManagementController::class, 'unsuspend'])->name('api.application.servers.unsuspend');
90+
Route::post('/{server}/reinstall', [Application\Servers\ServerManagementController::class, 'reinstall'])->name('api.application.servers.reinstall');
9091

91-
Route::delete('/{server}', 'Servers\ServerController@delete');
92-
Route::delete('/{server}/{force?}', 'Servers\ServerController@delete');
92+
Route::delete('/{server}', [Application\Servers\ServerController::class, 'delete']);
93+
Route::delete('/{server}/{force?}', [Application\Servers\ServerController::class, 'delete']);
9394

9495
// Database Management Endpoint
9596
Route::group(['prefix' => '/{server}/databases'], function () {
96-
Route::get('/', 'Servers\DatabaseController@index')->name('api.application.servers.databases');
97-
Route::get('/{database}', 'Servers\DatabaseController@view')->name('api.application.servers.databases.view');
97+
Route::get('/', [Application\Servers\DatabaseController::class, 'index'])->name('api.application.servers.databases');
98+
Route::get('/{database}', [Application\Servers\DatabaseController::class, 'view'])->name('api.application.servers.databases.view');
9899

99-
Route::post('/', 'Servers\DatabaseController@store');
100-
Route::post('/{database}/reset-password', 'Servers\DatabaseController@resetPassword');
100+
Route::post('/', [Application\Servers\DatabaseController::class, 'store']);
101+
Route::post('/{database}/reset-password', [Application\Servers\DatabaseController::class, 'resetPassword']);
101102

102-
Route::delete('/{database}', 'Servers\DatabaseController@delete');
103+
Route::delete('/{database}', [Application\Servers\DatabaseController::class, 'delete']);
103104
});
104105
});
105106

@@ -112,12 +113,12 @@
112113
|
113114
*/
114115
Route::group(['prefix' => '/nests'], function () {
115-
Route::get('/', 'Nests\NestController@index')->name('api.application.nests');
116-
Route::get('/{nest}', 'Nests\NestController@view')->name('api.application.nests.view');
116+
Route::get('/', [Application\Nests\NestController::class, 'index'])->name('api.application.nests');
117+
Route::get('/{nest}', [Application\Nests\NestController::class, 'view'])->name('api.application.nests.view');
117118

118119
// Egg Management Endpoint
119120
Route::group(['prefix' => '/{nest}/eggs'], function () {
120-
Route::get('/', 'Nests\EggController@index')->name('api.application.nests.eggs');
121-
Route::get('/{egg}', 'Nests\EggController@view')->name('api.application.nests.eggs.view');
121+
Route::get('/', [Application\Nests\EggController::class, 'index'])->name('api.application.nests.eggs');
122+
Route::get('/{egg}', [Application\Nests\EggController::class, 'view'])->name('api.application.nests.eggs.view');
122123
});
123124
});

0 commit comments

Comments
 (0)