我是 GraphQL 的新手。我需要用 PHP 和 GraphQL 制作一个 API。我遵循了本教程: https ://medium.com/swlh/setting-up-graphql-with-php-9baba3f21501
一切正常,但打开 URL 时,出现此错误:
{
"statusCode": 405,
"error": {
"type": "NOT_ALLOWED",
"description": "Method not allowed. Must be one of: OPTIONS"
}
}
我将此添加到索引页面:
header('Access-Control-Allow-Origin', '*');
header('Access-Control-Allow-Headers', 'content-type');
header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
但问题没有解决。也许这里缺少一些东西:
return function (App $app) {
$app->options('/{routes:.*}', function (Request $request, Response $response) {
// CORS Pre-Flight OPTIONS Request Handler
return $response;
});