app->middleware->add(\think\middleware\SessionInit::class); // 动态加入应用函数 foreach (glob($this->app->getAppPath() . '*/sys.php') as $file) { \Composer\Autoload\includeFile($file); } } /** * 服务启动方法 */ public function boot() { // 注册访问跨域中间键 $this->app->middleware->add(function (Request $request, \Closure $next) { $header = []; if (($origin = $request->header('origin', '*')) !== '*') { $header['Access-Control-Allow-Origin'] = $origin; $header['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE'; $header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With'; $header['Access-Control-Expose-Headers'] = 'User-Form-Token'; } if ($request->isOptions()) { return response()->code(204)->header($header); } else { return $next($request)->header($header); } }); // 注册系统任务指令 $this->commands([ 'think\admin\queue\WorkQueue', 'think\admin\queue\StopQueue', 'think\admin\queue\StateQueue', 'think\admin\queue\StartQueue', 'think\admin\queue\QueryQueue', 'think\admin\queue\ListenQueue', 'think\admin\plugs\AdminPlugs' ]); } }