think-swoole 跨域

think-swoole 跨域解决方案重写:

   \vendor\topthink\think-swoole\src\Http.php

    /**
     * request回调
     * @param $request
     * @param $response
     */
    public function onRequest($request, $response)
    {
        $response->header('Access-Control-Allow-Origin', '*');
        $response->header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, PATCH, OPTIONS');
        $response->header('Access-Control-Allow-Headers', 'Authorization, User-Agent, Keep-Alive, Content-Type, X-Requested-With, token');
        if ($request->server['request_method'] == 'OPTIONS') {
            $response->status(200);
            $response->end();
            return;
        };
        // 执行应用并响应
        $this->app->swoole($request, $response);
    }

  

posted @ 2022-01-10 11:21  xupp  阅读(276)  评论(0编辑  收藏  举报