Skip to content

Commit

Permalink
Add Access-Control-Allow-Origin header, if not already present.
Browse files Browse the repository at this point in the history
  • Loading branch information
cicnavi authored and pradtke committed Sep 30, 2022
1 parent 0948322 commit 36f12eb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Services/RoutingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,23 @@ private static function callController($container, string $controllerClassname):
$response->data['messages'] = $container->get(SessionMessagesService::class)->getMessages();
}

// If not already handled, allow CORS (for JS clients).
if (!$response->headers->has('Access-Control-Allow-Origin')) {
$response->headers->set('Access-Control-Allow-Origin', '*');
}


$response->send();

return;
}

if ($response instanceof ResponseInterface) {
// If not already handled, allow CORS (for JS clients).
if (!$response->hasHeader('Access-Control-Allow-Origin')) {
$response = $response->withHeader('Access-Control-Allow-Origin', '*');
}

$emitter = new SapiEmitter();

$emitter->emit($response);
Expand Down

0 comments on commit 36f12eb

Please sign in to comment.