Skip to content

Commit

Permalink
still register log viewer index route even for api-only access.
Browse files Browse the repository at this point in the history
  • Loading branch information
arukompas committed Apr 24, 2024
1 parent e7af731 commit 02d5e4f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class IndexController
{
public function __invoke()
{
if (config('log-viewer.api_only')) {
abort(404);
}

return view(LogViewer::getViewLayout(), [
'logViewerScriptVariables' => [
'headers' => (object) [],
Expand Down
18 changes: 8 additions & 10 deletions src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ protected function registerRoutes()
$this->loadRoutesFrom(self::basePath('/routes/api.php'));
});

if (! config('log-viewer.api_only', false)) {
Route::group([
'domain' => config('log-viewer.route_domain', null),
'prefix' => config('log-viewer.route_path'),
'namespace' => 'Opcodes\LogViewer\Http\Controllers',
'middleware' => config('log-viewer.middleware', null),
], function () {
$this->loadRoutesFrom(self::basePath('/routes/web.php'));
});
}
Route::group([
'domain' => config('log-viewer.route_domain', null),
'prefix' => config('log-viewer.route_path'),
'namespace' => 'Opcodes\LogViewer\Http\Controllers',
'middleware' => config('log-viewer.middleware', null),
], function () {
$this->loadRoutesFrom(self::basePath('/routes/web.php'));
});
}

protected function registerResources()
Expand Down
7 changes: 4 additions & 3 deletions tests/Feature/RoutesTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Symfony\Component\Routing\Exception\RouteNotFoundException;
use function Pest\Laravel\get;

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

reloadRoutes();

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

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

reloadRoutes();

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

/*
Expand Down

0 comments on commit 02d5e4f

Please sign in to comment.