File tree Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 12
12
13
13
'enabled ' => env ('LOG_VIEWER_ENABLED ' , true ),
14
14
15
+ 'api_only ' => env ('LOG_VIEWER_API_ONLY ' , false ),
16
+
15
17
'require_auth_in_production ' => true ,
16
18
17
19
/*
Original file line number Diff line number Diff line change @@ -95,14 +95,16 @@ protected function registerRoutes()
95
95
$ this ->loadRoutesFrom (self ::basePath ('/routes/api.php ' ));
96
96
});
97
97
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
- });
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
+ }
106
108
}
107
109
108
110
protected function registerResources ()
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ use Symfony \Component \Routing \Exception \RouteNotFoundException ;
4
+
3
5
test ('the default url can be changed ' , function () {
4
6
config ()->set ('log-viewer.route_path ' , 'new-log-route ' );
5
7
25
27
expect (route ('log-viewer.index ' ))->toBe ('http://localhost ' );
26
28
});
27
29
30
+ test ('only use api ' , function () {
31
+ config ()->set ('log-viewer.api_only ' , true );
32
+
33
+ reloadRoutes ();
34
+
35
+ route ('log-viewer.index ' );
36
+ })->throws (RouteNotFoundException::class);
37
+
38
+ test ('only both api and web ' , function () {
39
+ config ()->set ('log-viewer.api_only ' , false );
40
+
41
+ reloadRoutes ();
42
+
43
+ expect (route ('log-viewer.index ' ))->toBe ('http://localhost/log-viewer ' );
44
+ });
45
+
28
46
/*
29
47
|--------------------------------------------------------------------------
30
48
| HELPERS
33
51
34
52
function reloadRoutes (): void
35
53
{
54
+ // unset any routes that were set previously
55
+ app ('router ' )->setRoutes (new \Illuminate \Routing \RouteCollection ());
56
+
57
+ // boot the service provider to register the routes again
36
58
(new \Opcodes \LogViewer \LogViewerServiceProvider (app ()))->boot ();
37
59
}
You can’t perform that action at this time.
0 commit comments