route.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. SeretKeyMiddleware::class
  16. ]);
  17. // 加载聊天相关路由
  18. require __DIR__ . '/chat.php';
  19. // 加载其他路由文件
  20. $routeDir = __DIR__;
  21. $routeFiles = ['user', 'cart', 'product', 'order', 'pay', 'shop', 'address', 'recharge', 'forum', 'education', 'pub'];
  22. foreach ($routeFiles as $file) {
  23. $filePath = $routeDir . '/' . $file . '.php';
  24. if (file_exists($filePath)) {
  25. require $filePath;
  26. }
  27. }
  28. /**
  29. * miss 路由
  30. */
  31. Route::miss(function () {
  32. if (app()->request->isOptions()) {
  33. $header = Config::get('cookie.header');
  34. $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
  35. return Response::create('ok')->code(200)->header($header);
  36. } else
  37. return Response::create()->code(404);
  38. });