Skip to content

Commit 030862b

Browse files
authored
Merge pull request #233 from dotkernel/issue_232
Replace tuupola/cors with mezzio/cors.
2 parents 2e0d507 + e4ce948 commit 030862b

File tree

6 files changed

+21
-55
lines changed

6 files changed

+21
-55
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
"laminas/laminas-stdlib": "^3.2",
6363
"mezzio/mezzio": "^3.2",
6464
"mezzio/mezzio-authorization-rbac": "^1.0",
65+
"mezzio/mezzio-cors": "^1.0",
6566
"mezzio/mezzio-fastroute": "^3.0",
6667
"mezzio/mezzio-helpers": "^5.3",
6768
"mezzio/mezzio-twigrenderer": "^2.2",
6869
"ramsey/uuid-doctrine": "^1.6",
6970
"roave/psr-container-doctrine": "^2.2",
70-
"robmorgan/phinx": "^0.12",
71-
"tuupola/cors-middleware": "^1.1"
71+
"robmorgan/phinx": "^0.12"
7272
},
7373
"require-dev": {
7474
"laminas/laminas-development-mode": "^3.2",

config/autoload/cors.global.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
declare(strict_types=1);
44

5+
use Mezzio\Cors\Configuration\ConfigurationInterface;
6+
57
return [
6-
'cors' => [
7-
'origin' => ['*'],
8-
'methods' => ['DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT'],
9-
'headers.allow' => ['Accept', 'Content-Type', 'Authorization'],
10-
'headers.expose' => [],
11-
'credentials' => false,
12-
'cache' => 0,
13-
'error' => [
14-
Frontend\App\Factory\CorsFactory::class, 'error'
15-
]
8+
ConfigurationInterface::CONFIGURATION_IDENTIFIER => [
9+
'allowed_origins' => [
10+
/**
11+
* Leaving this line here makes your application accessible by any origin.
12+
*
13+
* To restrict, replace this line with a list of origins that should have access to your application.
14+
* Example: "domain1.com", "domain2.com"
15+
*/
16+
ConfigurationInterface::ANY_ORIGIN
17+
],
18+
'allowed_headers' => ['Accept', 'Content-Type', 'Authorization'], // Custom headers
19+
'allowed_max_age' => '600', // 10 minutes
20+
'credentials_allowed' => true, // Allow cookies
21+
'exposed_headers' => [], // Tell client that the API will always return this header
1622
],
1723
];

config/autoload/dependencies.global.php

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Dot\Mail\Factory\MailOptionsAbstractFactory;
66
use Dot\Mail\Factory\MailServiceAbstractFactory;
77
use Dot\Mail\Service\MailService;
8-
use Frontend\App\Factory\CorsFactory;
98
use Dot\ErrorHandler\ErrorHandlerInterface;
109
use Dot\ErrorHandler\LogErrorHandler;
1110
use Frontend\App\Middleware\AuthMiddleware;
@@ -33,7 +32,6 @@
3332
'factories' => [
3433
'dot-mail.options.default' => MailOptionsAbstractFactory::class,
3534
'dot-mail.service.default' => MailServiceAbstractFactory::class,
36-
Tuupola\Middleware\CorsMiddleware::class => CorsFactory::class,
3735
AuthMiddleware::class => AuthMiddlewareFactory::class,
3836
],
3937
],

config/config.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
$aggregator = new ConfigAggregator([
1616
\Laminas\HttpHandlerRunner\ConfigProvider::class,
17+
\Laminas\Diactoros\ConfigProvider::class,
1718
\Mezzio\Twig\ConfigProvider::class,
1819
\Mezzio\Router\FastRouteRouter\ConfigProvider::class,
1920
// Include cache configuration
@@ -22,6 +23,7 @@
2223
\Mezzio\Helper\ConfigProvider::class,
2324
\Mezzio\ConfigProvider::class,
2425
\Mezzio\Router\ConfigProvider::class,
26+
\Mezzio\Cors\ConfigProvider::class,
2527

2628
// Swoole config to overwrite some services (if installed)
2729
class_exists(\Mezzio\Swoole\ConfigProvider::class)

config/pipeline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Dot\ErrorHandler\ErrorHandlerInterface;
66
use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware;
77
use Mezzio\Application;
8+
use Mezzio\Cors\Middleware\CorsMiddleware;
89
use Mezzio\Handler\NotFoundHandler;
910
use Mezzio\Helper\ServerUrlMiddleware;
1011
use Mezzio\Helper\UrlHelperMiddleware;
@@ -15,7 +16,6 @@
1516
use Mezzio\Router\Middleware\MethodNotAllowedMiddleware;
1617
use Mezzio\Router\Middleware\RouteMiddleware;
1718
use Psr\Container\ContainerInterface;
18-
use Tuupola\Middleware\CorsMiddleware;
1919
use Frontend\App\Middleware\TranslatorMiddleware;
2020
use Dot\Rbac\Guard\Middleware\ForbiddenHandler;
2121
use Dot\Rbac\Guard\Middleware\RbacGuardMiddleware;

src/App/src/Factory/CorsFactory.php

-40
This file was deleted.

0 commit comments

Comments
 (0)