diff --git a/config/pipeline.php b/config/pipeline.php index 8ebfd96..3447900 100644 --- a/config/pipeline.php +++ b/config/pipeline.php @@ -14,6 +14,7 @@ use Zend\Stratigility\Middleware\ErrorHandler; // The error handler should be the first (most outer) middleware to catch // all Exceptions. $app->pipe(ErrorHandler::class); +$app->pipe(App\Middleware\PreFlightMiddleware::class); $app->pipe(LosMiddleware\BasePath\BasePath::class); $app->pipe(ServerUrlMiddleware::class); diff --git a/src/App/Action/KanbanAction.php b/src/App/Action/KanbanAction.php index 62c0878..25f8df9 100644 --- a/src/App/Action/KanbanAction.php +++ b/src/App/Action/KanbanAction.php @@ -2,11 +2,11 @@ namespace App\Action; +use App\Response\JsonCorsResponse; use App\Service\DataCollectorService; use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; -use Zend\Diactoros\Response\JsonResponse; class KanbanAction implements ServerMiddlewareInterface { @@ -20,6 +20,6 @@ class KanbanAction implements ServerMiddlewareInterface public function process(ServerRequestInterface $request, DelegateInterface $delegate) { $kanbanResult = $this->dataCollector->getKanbanBoard(); - return new JsonResponse($kanbanResult); + return new JsonCorsResponse($kanbanResult); } } diff --git a/src/App/Entity/KanbanEntry.php b/src/App/Entity/KanbanEntry.php index abe5428..610d559 100644 --- a/src/App/Entity/KanbanEntry.php +++ b/src/App/Entity/KanbanEntry.php @@ -75,7 +75,7 @@ class KanbanEntry implements \JsonSerializable /** * JIRA: customfield_10847 - * @var string + * @var bool */ private $mhwebHot; diff --git a/src/App/Middleware/PreFlightMiddleware.php b/src/App/Middleware/PreFlightMiddleware.php new file mode 100644 index 0000000..6674105 --- /dev/null +++ b/src/App/Middleware/PreFlightMiddleware.php @@ -0,0 +1,34 @@ +getMethod()); + if ($requestMethod == 'OPTIONS') { + return $response + ->withHeader('Accept', 'OPTIONS,GET,POST,PUT,PATCH,DELETE') + ->withHeader('Access-Control-Allow-Origin', '*') + ->withHeader('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE') + ->withHeader('Access-Control-Allow-Headers', implode(",", self::ALLOW_HEADERS)); + } + return $next($request, $response); + } +} diff --git a/src/App/Response/JsonCorsResponse.php b/src/App/Response/JsonCorsResponse.php new file mode 100644 index 0000000..7b71dd9 --- /dev/null +++ b/src/App/Response/JsonCorsResponse.php @@ -0,0 +1,32 @@ +setAdapter($curlAdapter = new Client\Adapter\Curl()); - $curlAdapter->setOptions(['timeout' => 60]); + $curlAdapter->setOptions(['timeout' => 300]); if($config->get('http.proxy.enabled', false)) { $curlAdapter ->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))