Skip to content

Commit

Permalink
Better cors handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed May 2, 2024
1 parent 0a98ac5 commit 4cf2ded
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions api/config/packages/nelmio_cors.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
parameters:
cors_origins: []
env(CORS_ORIGIN_EXTRA): '["*","https://localhost","https://localhost:8000"]'
env(CORS_ORIGIN): '*'
cors_origins: '%env(json:CORS_ORIGIN_EXTRA)%'

nelmio_cors:
defaults:
origin_regex: true
allow_origin: '%cors_origins%'
allow_origin: ['%env(CORS_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization', 'x-method', 'x-endpoint']
expose_headers: ['Link']
Expand Down
4 changes: 2 additions & 2 deletions api/src/Command/InitializationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$application->setDomains($domains);
$application->setOrganization($organization);

$adminHost = 'https://'.(str_starts_with($parsedAppUrl['host'], 'api') ? str_replace(search: 'api', replace: 'admin', subject: $parsedAppUrl['host']) : $parsedAppUrl['host']);
$adminHost = $parsedAppUrl['scheme'].'://'.(str_starts_with($parsedAppUrl['host'], 'api') ? str_replace(search: 'api', replace: 'admin', subject: $parsedAppUrl['host']) : $parsedAppUrl['host'].':8000');

$application->setOrigins(array_unique(['http://localhost', $parsedAppUrl['schema'].'://'.$parsedAppUrl['host']], $adminHost));
$application->setOrigins(origins: array_values(array: array_unique(array: ['http://localhost', $parsedAppUrl['scheme'].'://'.$parsedAppUrl['host'], $adminHost])));
// $application->setSecret('LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV3QUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktvd2dnU21BZ0VBQW9JQkFRRFNQU1lacUs3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