Configuring middleware
Before you're able to configure this, make sure to first publish the configuration file.
Since Log Viewer v2, the requests can be stateless and no longer have any middleware requirements, but the default configuration (config/log-viewer.php
) does include some middleware to make sure authorization works out of the box, which is described below.
You can easily add your own Laravel Middleware. This will only take effect when loading the Log Viewer UI.
/* |-------------------------------------------------------------------------- | Log Viewer route middleware. |-------------------------------------------------------------------------- | Optional middleware to use when loading the initial Log Viewer page. | */ 'middleware' => [ 'web', \Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class, ],
Here are the default middlewares:
- The
web
middleware group makes sure your requests are stateful and can resolve an authenticated user for authorization. Refer to yourapp/Http/Kernel.php
file to see which middlewares are included in theweb
middleware group. - The
AuthorizeLogViewer
middleware makes sure that only authorized users can access the Log Viewer. You still need to configure the authorization rule described here.
API middleware
You can also add your own Laravel Middleware to the Log Viewer API requests.
/* |-------------------------------------------------------------------------- | Log Viewer API middleware. |-------------------------------------------------------------------------- | Optional middleware to use on every API request. The same API is also | used from within the Log Viewer user interface. | */ 'api_middleware' => [ \Opcodes\LogViewer\Http\Middleware\EnsureFrontendRequestsAreStateful::class, \Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class, ],
Here are the default middlewares:
- The
EnsureFrontendRequestsAreStateful
middleware makes sure that API requests from the Log Viewer user interface are stateful. This is required for authorization to work properly when navigating the logs. You can remove this middleware if you don't need authorization. - The
AuthorizeLogViewer
middleware makes sure that only authorized users can access the Log Viewer. You still need to configure the authorization rule described here.