-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from sitegeist/neos7
Neos 7 Compatibility
- Loading branch information
Showing
4 changed files
with
51 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Wwwision\GraphQL\Http; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Psr\Http\Message\ResponseFactoryInterface; | ||
|
||
/** | ||
* A simple HTTP Component that captures OPTIONS requests and responds with a general "Allow: GET, POST" header if a matching graphQL endpoint is configured | ||
*/ | ||
class HttpOptionsMiddleware implements MiddlewareInterface | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration(path="endpoints") | ||
* @var array | ||
*/ | ||
protected $endpoints; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var ResponseFactoryInterface | ||
*/ | ||
protected $responseFactory; | ||
|
||
/** | ||
* @param ServerRequestInterface $request | ||
* @param RequestHandlerInterface $next | ||
* @return ResponseInterface | ||
*/ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface | ||
{ | ||
// no OPTIONS request => skip | ||
if ($request->getMethod() !== 'OPTIONS') { | ||
return $next->handle($request); | ||
} | ||
$endpoint = ltrim($request->getUri()->getPath(), '\/'); | ||
// no matching graphQL endpoint configured => skip | ||
if (!isset($this->endpoints[$endpoint])) { | ||
return $next->handle($request); | ||
} | ||
return $this->responseFactory->createResponse()->withHeader('Allow', 'GET, POST'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters