| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\api\route;
- use app\api\middleware\AllowOriginMiddleware;
- use app\api\middleware\SeretKeyMiddleware;
- use think\facade\Config;
- use think\facade\Route;
- use think\Response;
- /**
- * 无需授权的接口
- */
- Route::group(function () {
- Route::rule('index', 'Index/index');
- })->middleware([
- AllowOriginMiddleware::class,
- SeretKeyMiddleware::class
- ]);
- // 加载聊天相关路由
- require __DIR__ . '/chat.php';
- // 加载其他路由文件
- $routeDir = __DIR__;
- $routeFiles = ['user', 'cart', 'product', 'order', 'pay', 'shop', 'address', 'recharge', 'forum', 'education', 'pub'];
- foreach ($routeFiles as $file) {
- $filePath = $routeDir . '/' . $file . '.php';
- if (file_exists($filePath)) {
- require $filePath;
- }
- }
- /**
- * miss 路由
- */
- Route::miss(function () {
- if (app()->request->isOptions()) {
- $header = Config::get('cookie.header');
- $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
- return Response::create('ok')->code(200)->header($header);
- } else
- return Response::create()->code(404);
- });
|