Skip to content

Commit ccafb4d

Browse files
committed
Fix unnecesary routes being registered
1 parent 4bf36ff commit ccafb4d

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

app/Providers/RestifyServiceProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Controllers\Api\V1\HealthController;
66
use App\Http\Controllers\Api\V1\PingController;
7+
use App\Restify\RoutesBoot as CustomRoutesBoot;
78
use Binaryk\LaravelRestify\Bootstrap\RoutesBoot;
89
use Binaryk\LaravelRestify\Restify;
910
use Binaryk\LaravelRestify\RestifyApplicationServiceProvider;
@@ -41,6 +42,14 @@ protected function routes(): void
4142

4243
public function boot(): void
4344
{
45+
// Swap Restify's route booter for one that omits the built-in
46+
// default routes (profile, global search, restifyjs/setup). The only
47+
// v1 routes should be those we explicitly add: registered
48+
// repositories and our own custom controllers (ping/health). This
49+
// must be bound before parent::boot() triggers route registration,
50+
// and persists for the RestifyInjector middleware at request time.
51+
$this->app->bind(RoutesBoot::class, CustomRoutesBoot::class);
52+
4453
parent::boot();
4554

4655
// No model repositories are registered yet. Add repository classes

app/Restify/RoutesBoot.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Restify;
4+
5+
use Binaryk\LaravelRestify\Bootstrap\RoutesBoot as BaseRoutesBoot;
6+
use Binaryk\LaravelRestify\Bootstrap\RoutesDefinition;
7+
use Illuminate\Support\Facades\Route;
8+
9+
/**
10+
* Customized Restify route booter.
11+
*
12+
* The base class registers a set of built-in, non-repository endpoints
13+
* (profile, global search, restifyjs/setup) via RoutesDefinition::once().
14+
* We don't want those: the only v1 routes should be the ones we explicitly
15+
* add (registered repositories and our own custom controllers ).
16+
* This override registers the per-repository CRUD routes but
17+
* skips once().
18+
*/
19+
class RoutesBoot extends BaseRoutesBoot
20+
{
21+
public function defaultRoutes($config): self
22+
{
23+
Route::group($config, function (): void {
24+
// Repository CRUD/actions/getters/etc. via the {repository}
25+
// wildcard. Intentionally omit ->once() so profile, search and
26+
// restifyjs/setup are not registered.
27+
app(RoutesDefinition::class)();
28+
});
29+
30+
return $this;
31+
}
32+
}

config/restify.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
'auth' => [
88
'table' => 'users',
99
'provider' => 'sanctum',
10-
'frontend_app_url' => env('FRONTEND_APP_URL', env('APP_URL')),
11-
'password_reset_url' => env('FRONTEND_APP_URL') . '/password/reset?token={token}&email={email}',
12-
'user_verify_url' => env('FRONTEND_APP_URL') . '/verify/{id}/{emailHash}',
1310
'user_model' => \App\Models\User::class,
1411
'token_ttl' => env('RESTIFY_TOKEN_TTL', null),
1512
],

0 commit comments

Comments
 (0)