route.php 969 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\admin\route;
  3. use app\admin\middleware\AllowOriginMiddleware;
  4. use app\admin\middleware\SeretKeyMiddleware;
  5. use think\facade\Config;
  6. use think\facade\Route;
  7. use think\Response;
  8. /**
  9. * 无需授权的接口
  10. */
  11. Route::group(function () {
  12. //后台管理员登录
  13. Route::rule('login/login', 'Login/index');
  14. //验证码
  15. Route::rule('index', 'Index/index');
  16. })->middleware([
  17. \app\admin\middleware\AllowOriginMiddleware::class
  18. ]);
  19. Route::group(function () {
  20. Route::get('login/captcha', 'Login/captcha');
  21. })->middleware([
  22. \app\admin\middleware\AllowOriginMiddleware::class
  23. ]);
  24. /**
  25. * miss 路由
  26. */
  27. Route::miss(function () {
  28. if (app()->request->isOptions()) {
  29. $header = Config::get('cookie.header');
  30. $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
  31. return Response::create('ok')->code(200)->header($header);
  32. } else
  33. return Response::create()->code(404);
  34. });