-
Notifications
You must be signed in to change notification settings - Fork 8
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 #31 from Sebobo/task/flow-7-compatibility
!!! TASK: Flow 7 compatibility
- Loading branch information
Showing
5 changed files
with
49 additions
and
57 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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace t3n\GraphQL\Http; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
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; | ||
|
||
class HttpOptionsMiddleware implements MiddlewareInterface | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration("endpoints") | ||
* | ||
* @var mixed[] | ||
*/ | ||
protected $endpoints; | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if ($request->getMethod() !== 'OPTIONS') { | ||
return $handler->handle($request); | ||
} | ||
|
||
// We explode the request target because custom routes like /some/custom/route/<endpoint> 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])); | ||
} | ||
} |
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
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