Skip to content

Commit 02d5e4f

Browse files
committed
still register log viewer index route even for api-only access.
1 parent e7af731 commit 02d5e4f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/Http/Controllers/IndexController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class IndexController
99
{
1010
public function __invoke()
1111
{
12+
if (config('log-viewer.api_only')) {
13+
abort(404);
14+
}
15+
1216
return view(LogViewer::getViewLayout(), [
1317
'logViewerScriptVariables' => [
1418
'headers' => (object) [],

src/LogViewerServiceProvider.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,14 @@ protected function registerRoutes()
9595
$this->loadRoutesFrom(self::basePath('/routes/api.php'));
9696
});
9797

98-
if (! config('log-viewer.api_only', false)) {
99-
Route::group([
100-
'domain' => config('log-viewer.route_domain', null),
101-
'prefix' => config('log-viewer.route_path'),
102-
'namespace' => 'Opcodes\LogViewer\Http\Controllers',
103-
'middleware' => config('log-viewer.middleware', null),
104-
], function () {
105-
$this->loadRoutesFrom(self::basePath('/routes/web.php'));
106-
});
107-
}
98+
Route::group([
99+
'domain' => config('log-viewer.route_domain', null),
100+
'prefix' => config('log-viewer.route_path'),
101+
'namespace' => 'Opcodes\LogViewer\Http\Controllers',
102+
'middleware' => config('log-viewer.middleware', null),
103+
], function () {
104+
$this->loadRoutesFrom(self::basePath('/routes/web.php'));
105+
});
108106
}
109107

110108
protected function registerResources()

tests/Feature/RoutesTest.php

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

3-
use Symfony\Component\Routing\Exception\RouteNotFoundException;
3+
use function Pest\Laravel\get;
44

55
test('the default url can be changed', function () {
66
config()->set('log-viewer.route_path', 'new-log-route');
@@ -32,15 +32,16 @@
3232

3333
reloadRoutes();
3434

35-
route('log-viewer.index');
36-
})->throws(RouteNotFoundException::class);
35+
get(route('log-viewer.index'))->assertStatus(404);
36+
});
3737

3838
test('only both api and web', function () {
3939
config()->set('log-viewer.api_only', false);
4040

4141
reloadRoutes();
4242

4343
expect(route('log-viewer.index'))->toBe('http://localhost/log-viewer');
44+
get(route('log-viewer.index'))->assertStatus(200);
4445
});
4546

4647
/*

0 commit comments

Comments
 (0)