diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 570e6cd..8847256 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -53,6 +53,7 @@ return [ }, Lean\ApplicationStrategy\NotFoundDecoratorInterface::class => DI\autowire(Lean\Api\ApplicationStrategy\NotFoundDecorator::class), + Lean\ApplicationStrategy\MethodNotAllowedInterface::class => DI\autowire(Lean\Api\ApplicationStrategy\MethodNotAllowedDecorator::class), Lean\Api\Factory\MessageFactoryInterface::class => DI\autowire(Lean\Api\Lib\Message::class), Lean\Api\Factory\DebugFormFactoryInterface::class => DI\autowire(Lean\Api\Factory\DebugFormFactory::class), # League\Route\Strategy\ApplicationStrategy::class => DI\autowire(Lean\Api\ApplicationStrategy::class), diff --git a/src/ApplicationStrategy/MethodNotAllowedDecorator.php b/src/ApplicationStrategy/MethodNotAllowedDecorator.php new file mode 100644 index 0000000..61a662a --- /dev/null +++ b/src/ApplicationStrategy/MethodNotAllowedDecorator.php @@ -0,0 +1,29 @@ +getMethod() === 'OPTIONS') { + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: *'); + header('Access-Control-Allow-Headers: *'); + header('Access-Control-Allow-Credentials: true'); + exit(0); + } + + return $handler->handle($request);; + } +} \ No newline at end of file diff --git a/src/Middleware/CORS.php b/src/Middleware/CORS.php new file mode 100644 index 0000000..766f413 --- /dev/null +++ b/src/Middleware/CORS.php @@ -0,0 +1,26 @@ +getMethod() ); + if ($request->getMethod() === "option") { + die("an option :)"); + } + + return $handler->handle($request); + } +}