* cors+preflight
* timeout change
This commit is contained in:
parent
f196244f7c
commit
e23054315b
@ -14,6 +14,7 @@ use Zend\Stratigility\Middleware\ErrorHandler;
|
|||||||
// The error handler should be the first (most outer) middleware to catch
|
// The error handler should be the first (most outer) middleware to catch
|
||||||
// all Exceptions.
|
// all Exceptions.
|
||||||
$app->pipe(ErrorHandler::class);
|
$app->pipe(ErrorHandler::class);
|
||||||
|
$app->pipe(App\Middleware\PreFlightMiddleware::class);
|
||||||
$app->pipe(LosMiddleware\BasePath\BasePath::class);
|
$app->pipe(LosMiddleware\BasePath\BasePath::class);
|
||||||
$app->pipe(ServerUrlMiddleware::class);
|
$app->pipe(ServerUrlMiddleware::class);
|
||||||
|
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Action;
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Response\JsonCorsResponse;
|
||||||
use App\Service\DataCollectorService;
|
use App\Service\DataCollectorService;
|
||||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response\JsonResponse;
|
|
||||||
|
|
||||||
class KanbanAction implements ServerMiddlewareInterface
|
class KanbanAction implements ServerMiddlewareInterface
|
||||||
{
|
{
|
||||||
@ -20,6 +20,6 @@ class KanbanAction implements ServerMiddlewareInterface
|
|||||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||||
{
|
{
|
||||||
$kanbanResult = $this->dataCollector->getKanbanBoard();
|
$kanbanResult = $this->dataCollector->getKanbanBoard();
|
||||||
return new JsonResponse($kanbanResult);
|
return new JsonCorsResponse($kanbanResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class KanbanEntry implements \JsonSerializable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JIRA: customfield_10847
|
* JIRA: customfield_10847
|
||||||
* @var string
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $mhwebHot;
|
private $mhwebHot;
|
||||||
|
|
||||||
|
|||||||
34
src/App/Middleware/PreFlightMiddleware.php
Normal file
34
src/App/Middleware/PreFlightMiddleware.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Middleware;
|
||||||
|
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
class PreFlightMiddleware
|
||||||
|
{
|
||||||
|
const ALLOW_HEADERS = [
|
||||||
|
'DNT',
|
||||||
|
'X-CustomHeader',
|
||||||
|
'Keep-Alive',
|
||||||
|
'User-Agent',
|
||||||
|
'X-Requested-With',
|
||||||
|
'If-Modified-Since',
|
||||||
|
'Cache-Control',
|
||||||
|
'Content-Type',
|
||||||
|
'Authorization',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
|
||||||
|
{
|
||||||
|
$requestMethod = strtoupper($request->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/App/Response/JsonCorsResponse.php
Normal file
32
src/App/Response/JsonCorsResponse.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Response;
|
||||||
|
|
||||||
|
use Zend\Diactoros\Response\JsonResponse;
|
||||||
|
|
||||||
|
class JsonCorsResponse extends JsonResponse
|
||||||
|
{
|
||||||
|
const ALLOW_HEADERS = [
|
||||||
|
'DNT',
|
||||||
|
'X-CustomHeader',
|
||||||
|
'Keep-Alive',
|
||||||
|
'User-Agent',
|
||||||
|
'X-Requested-With',
|
||||||
|
'If-Modified-Since',
|
||||||
|
'Cache-Control',
|
||||||
|
'Content-Type',
|
||||||
|
'Authorization',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
$data,
|
||||||
|
$status = 200,
|
||||||
|
array $headers = [],
|
||||||
|
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||||
|
) {
|
||||||
|
$headers['Access-Control-Allow-Origin'] = '*';
|
||||||
|
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
||||||
|
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
|
||||||
|
parent::__construct($data, $status, $headers, $encodingOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,7 +14,7 @@ class DataCollectorServiceFactory
|
|||||||
$config = new Config($configArray['app.config']);
|
$config = new Config($configArray['app.config']);
|
||||||
$httpClient = new Client();
|
$httpClient = new Client();
|
||||||
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
||||||
$curlAdapter->setOptions(['timeout' => 60]);
|
$curlAdapter->setOptions(['timeout' => 300]);
|
||||||
if($config->get('http.proxy.enabled', false)) {
|
if($config->get('http.proxy.enabled', false)) {
|
||||||
$curlAdapter
|
$curlAdapter
|
||||||
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user