Skip to content

Commit 2b36335

Browse files
Use bundle to correctly handle CORS for API.
Fixes #2504.
1 parent f863f37 commit 2b36335

File tree

7 files changed

+89
-23
lines changed

7 files changed

+89
-23
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"league/commonmark": "^2.3",
7171
"mbostock/d3": "^3.5",
7272
"nelmio/api-doc-bundle": "^4.11",
73+
"nelmio/cors-bundle": "^2.4",
7374
"novus/nvd3": "^1.8",
7475
"phpdocumentor/reflection-docblock": "^5.3",
7576
"phpstan/phpdoc-parser": "^1.25",

composer.lock

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

symfony.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@
208208
"webapp/config/routes/nelmio_api_doc.yaml"
209209
]
210210
},
211+
"nelmio/cors-bundle": {
212+
"version": "2.4",
213+
"recipe": {
214+
"repo": "github.com/symfony/recipes",
215+
"branch": "main",
216+
"version": "1.5",
217+
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
218+
},
219+
"files": [
220+
"webapp/config/packages/nelmio_cors.yaml"
221+
]
222+
},
211223
"nette/schema": {
212224
"version": "v1.2.2"
213225
},

webapp/config/bundles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22

33
return [
44
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
@@ -17,4 +17,5 @@
1717
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
1818
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
1919
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
20+
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
2021
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
nelmio_cors:
2+
paths:
3+
'^/api':
4+
allow_origin: [ '*' ]
5+
allow_credentials: true
6+
allow_methods: [ 'POST', 'PUT', 'GET', 'DELETE' ]
7+
max_age: 3600

webapp/phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<server name="SHELL_VERBOSITY" value="-1"/>
1818
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
1919
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
20+
21+
<!-- ###+ nelmio/cors-bundle ### -->
22+
<env name="CORS_ALLOW_ORIGIN" value="'^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'"/>
23+
<!-- ###- nelmio/cors-bundle ### -->
2024
</php>
2125
<testsuites>
2226
<testsuite name="Unit tests">

webapp/src/EventListener/ApiHeadersListener.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)