jh-admin/app/middleware/ResourceMiddleware.php

18 lines
564 B
PHP

<?php
namespace app\middleware;
use think\Response;
class ResourceMiddleware
{
public function handle($request, \Closure $next)
{
$allowExt='/^(jpg|jpeg|png|gif|css|js|ico)$/';
if(preg_match($allowExt,pathinfo($request->pathinfo(),PATHINFO_EXTENSION))){
$filename = root_path() . $request->pathinfo();
return new \think\swoole\response\File($filename);
/** @var Response $response */
$response = $next($request);
return $response;
}
return $next($request);
}
}