route.php 696 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\api\route;
  3. use app\api\middleware\AllowOriginMiddleware;
  4. use app\api\middleware\SeretKeyMiddleware;
  5. use think\facade\Config;
  6. use think\facade\Route;
  7. use think\Response;
  8. /**
  9. * 无需授权的接口
  10. */
  11. Route::group(function () {
  12. Route::rule('index', 'Index/index');
  13. })->middleware([
  14. AllowOriginMiddleware::class
  15. ]);
  16. /**
  17. * miss 路由
  18. */
  19. Route::miss(function () {
  20. if (app()->request->isOptions()) {
  21. $header = Config::get('cookie.header');
  22. $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
  23. return Response::create('ok')->code(200)->header($header);
  24. } else
  25. return Response::create()->code(404);
  26. });