Skip to content

Commit

Permalink
feat: api only flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hungthai1401 committed Apr 3, 2024
1 parent eeb391b commit adbd697
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

'enabled' => env('LOG_VIEWER_ENABLED', true),

'api_only' => env('LOG_VIEWER_API_ONLY', false),

'require_auth_in_production' => true,

/*
Expand Down
4 changes: 4 additions & 0 deletions src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ protected function registerRoutes()
$this->loadRoutesFrom(self::basePath('/routes/api.php'));
});

if (config('log-viewer.api_only', false)) {
return;
}

Route::group([
'domain' => config('log-viewer.route_domain', null),
'prefix' => config('log-viewer.route_path'),
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/RoutesTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Symfony\Component\Routing\Exception\RouteNotFoundException;

test('the default url can be changed', function () {
config()->set('log-viewer.route_path', 'new-log-route');

Expand All @@ -25,6 +27,22 @@
expect(route('log-viewer.index'))->toBe('http://localhost');
});

test('only use api', function () {
config()->set('log-viewer.api_only', true);

reloadRoutes();

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

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

reloadRoutes();

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

/*
|--------------------------------------------------------------------------
| HELPERS
Expand Down
1 change: 1 addition & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
uses(TestCase::class)->in(__DIR__);
uses()->afterEach(fn () => clearGeneratedLogFiles())->in('Feature', 'Unit');
uses()->beforeEach(fn () => Artisan::call('log-viewer:publish'))->in('Feature');
uses()->beforeEach(fn () => Artisan::call('config:cache'))->in('Feature');
uses()->beforeEach(function () {
// let's not include any of the default mac logs or similar
config(['log-viewer.include_files' => ['*.log', '**/*.log']]);
Expand Down

0 comments on commit adbd697

Please sign in to comment.