diff --git a/Classes/Http/HttpOptionsComponent.php b/Classes/Http/HttpOptionsComponent.php deleted file mode 100644 index cabf549..0000000 --- a/Classes/Http/HttpOptionsComponent.php +++ /dev/null @@ -1,46 +0,0 @@ -getHttpRequest(); - - if ($httpRequest->getMethod() !== 'OPTIONS') { - return; - } - - // We explode the request target because custom routes like /some/custom/route/ are - // are common. So we double check here if the last part in the route matches a configured - // endpoint - $endpoint = explode('/', ltrim($httpRequest->getRequestTarget(), '\/')); - - if (! isset($this->endpoints[end($endpoint)])) { - return; - } - - $httpResponse = $componentContext->getHttpResponse(); - $httpResponse = $httpResponse->withAddedHeader('Allow', 'GET, POST'); - - $componentContext->replaceHttpResponse($httpResponse); - $componentContext->setParameter(ComponentChain::class, 'cancel', true); - } -} diff --git a/Classes/Http/HttpOptionsMiddleware.php b/Classes/Http/HttpOptionsMiddleware.php new file mode 100644 index 0000000..4620659 --- /dev/null +++ b/Classes/Http/HttpOptionsMiddleware.php @@ -0,0 +1,40 @@ +getMethod() !== 'OPTIONS') { + return $handler->handle($request); + } + + // We explode the request target because custom routes like /some/custom/route/ are + // are common. So we double check here if the last part in the route matches a configured + // endpoint + $endpoint = explode('/', ltrim($request->getRequestTarget(), '\/')); + + if (! isset($this->endpoints[end($endpoint)])) { + return $handler->handle($request); + } + + return new Response(200, ['Content-Type' => 'application/json', 'Allow' => 'GET, POST'], json_encode(['success' => true])); + } +} diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index c179fbe..3ae1735 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -1,12 +1,10 @@ Neos: Flow: http: - chain: - 'process': - chain: - 'graphQLOptions': - position: 'before routing' - component: 't3n\GraphQL\Http\HttpOptionsComponent' + middlewares: + 'graphQLOptions': + position: 'before routing' + middleware: 't3n\GraphQL\Http\HttpOptionsMiddleware' log: graphQLRequestLogger: logger: Neos\Flow\Log\Logger diff --git a/composer.json b/composer.json index d376a11..51020a3 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "bin-dir": "bin" }, "require": { - "neos/flow": "~6.0", + "neos/flow": "~7.0", "t3n/graphql-tools": "~1.0.2", "php": ">=7.2", "ext-json": "*" }, "require-dev": { - "t3n/coding-standard": "~1.0.0" + "t3n/coding-standard": "~1.1.0" }, "autoload": { "psr-4": { diff --git a/composer.json.ci b/composer.json.ci index 2432f87..34672bf 100644 --- a/composer.json.ci +++ b/composer.json.ci @@ -6,14 +6,14 @@ "bin-dir": "bin" }, "require": { - "neos/flow": "~6.0", - "neos/buildessentials": "~6.0", + "neos/flow": "~7.0", + "neos/buildessentials": "~7.0", "t3n/graphql": "@dev", "t3n/coding-standard": "~1.1.0" }, "require-dev": { "squizlabs/php_codesniffer": "~3.5", - "phpunit/phpunit": "~8.5", + "phpunit/phpunit": "~9.3", "mikey179/vfsstream": "~1.6" }, "repositories": {