Swoft-Api项目部署九:前、后置中间件
中间件位置:app/Http/Middleware/
加载中间件:bean
'httpDispatcher' => [ // Add global http middleware 'middlewares' => [ \App\Http\Middleware\FavIconMiddleware::class, \Swoft\Http\Session\SessionMiddleware::class, // \Swoft\Whoops\WhoopsMiddleware::class, // Allow use @View tag \Swoft\View\Middleware\ViewMiddleware::class, \App\Http\Middleware\AuthMiddleware::class ], 'afterMiddlewares' => [ \Swoft\Http\Server\Middleware\ValidatorMiddleware::class, \App\Http\Middleware\AfterMiddleware::class ] ],
前置中间件
位置:app/Http/Middleware/AuthMiddleware.php
应用场景:权限检测、IP黑名单
后置中间件
位置:app/Http/Middleware/AfterMiddleware.php
应用场景:访问日志、记录请求参数、统计接口请求次数