Easyswoole反代下 设置多个Access-Control-Allow-Origin
public static function onRequest(Request $request, Response $response): bool
    {
        $http_origin = $request->getHeaders()['origin'][0];
        if (preg_match('/.*?46web.com/', $http_origin)) {
            $response->withHeader('Access-Control-Allow-Origin', $http_origin);
        }

//        $response->withHeader('Access-Control-Allow-Origin', 'https://46web.com');
        $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
        $response->withHeader('Access-Control-Allow-Credentials', 'true');
        $response->withHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
        if ($request->getMethod() === 'OPTIONS') {
            $response->withStatus(Status::CODE_OK);
            return false;
        }
        return true;

    }

在easyswoole根目录下的EVENT文件

打赏

本文 暂无 评论

回复给

Top