Skip to content

Commit

Permalink
added CORS header for specific routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed May 19, 2024
1 parent 98b762c commit 536c012
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use kissj\Entry\EntryController;
use kissj\Event\EventController;
use kissj\Export\ExportController;
use kissj\Middleware\AddCorsHeaderForAppDomainsMiddleware;
use kissj\Middleware\AdminPaymentsOnlyMiddleware;
use kissj\Middleware\AdminsOnlyMiddleware;
use kissj\Middleware\ApiAuthorizedOnlyMiddleware;
Expand Down Expand Up @@ -309,10 +310,12 @@ public function addRoutesInto(App $app): App

$app->post('/participant/{participantId}', EntryController::class . '::entryParticipantFromWebApp')
->add(ApiAuthorizedOnlyMiddleware::class)
->add(AddCorsHeaderForAppDomainsMiddleware::class)
->setName('entry-participant-from-web-app');

$app->post('/troop/{participantId}', EntryController::class . '::entryTroopFromWebApp')
->add(ApiAuthorizedOnlyMiddleware::class)
->add(AddCorsHeaderForAppDomainsMiddleware::class)
->setName('entry-troop-from-web-app');
});

Expand Down
21 changes: 21 additions & 0 deletions src/Middleware/AddCorsHeaderForAppDomainsMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace kissj\Middleware;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as ResponseHandler;

class AddCorsHeaderForAppDomainsMiddleware extends BaseMiddleware
{

public function process(Request $request, ResponseHandler $handler): Response
{
$response = $handler->handle($request);
$response = $response->withAddedHeader('Access-Control-Allow-Origin', 'https://kissj.skauting.net');

return $response;
}
}

0 comments on commit 536c012

Please sign in to comment.