From c9456ec9fd1a69a4e768bec0c9b238172c095b42 Mon Sep 17 00:00:00 2001 From: Dai Date: Wed, 24 Jul 2024 12:41:39 +0800 Subject: [PATCH] fix bug --- app/api/controller/UserController.php | 10 ++++++++++ config/middleware.php | 5 ++++- config/route.php | 11 ++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index d88fc5a..eb26299 100644 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\BaseController; use app\common\service\UserService; +use app\constant\ResponseCode; use support\Request; class UserController extends BaseController @@ -29,4 +30,13 @@ class UserController extends BaseController return $this->json($res); } + public function getBackgroundImage(Request $request) + { + return $this->json([ + 'code' => ResponseCode::SUCCESS, + 'data' => [], + 'msg' => 'success' + ]); + } + } \ No newline at end of file diff --git a/config/middleware.php b/config/middleware.php index 6b31d8b..bdf7d22 100644 --- a/config/middleware.php +++ b/config/middleware.php @@ -13,9 +13,12 @@ */ return [ + // 全局中间件 + '' => [ + app\middleware\AccessControlMiddleware::class, + ], // mch应用中间件 'api' => [ app\middleware\ApiAuthCheckMiddleware::class, - \app\middleware\AccessControlMiddleware::class ], ]; \ No newline at end of file diff --git a/config/route.php b/config/route.php index 6d7dfcf..9ee6998 100644 --- a/config/route.php +++ b/config/route.php @@ -22,7 +22,16 @@ Route::any('/h5', function (){ return view('../../public/h5/index'); }); - +Route::fallback(function (Request $request) { + $response = strtoupper($request->method()) === 'OPTIONS' ? response('', 204) : response('', 404); + $response->withHeaders([ + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Allow-Origin' => "*", + 'Access-Control-Allow-Methods' => '*', + 'Access-Control-Allow-Headers' => '*', + ]); + return $response; +});