Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zrnik/php-slim-cors
Slim Framework 4 CORS Middleware
https://github.com/zrnik/php-slim-cors
cors middleware php php8 slim-framework slim4
Last synced: about 1 month ago
JSON representation
Slim Framework 4 CORS Middleware
- Host: GitHub
- URL: https://github.com/zrnik/php-slim-cors
- Owner: Zrnik
- License: mit
- Created: 2024-03-15T14:17:12.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-12T06:59:28.000Z (7 months ago)
- Last Synced: 2024-10-13T04:21:23.544Z (about 1 month ago)
- Topics: cors, middleware, php, php8, slim-framework, slim4
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slim Framework 4 CORS Middleware
I just wanted to remove CORS error from my `React`
application to my Slim Framework 4 API.## Installation
```
composer require zrnik/php-slim-cors
```Requires Slim Framework 4 & PHP 8.1+
## Usage
Add this middleware to your `\Slim\App`:
```php
$app = new \Slim\App();
$app->add(new \Zrnik\SlimCors\CorsMiddleware());
```That's it. There are optional parameters for the `CorsMiddleware` object:
```php
$app = new \Slim\App();
$app->add(
new \Zrnik\SlimCors\CorsMiddleware(
allowedOrigins: [
'my-frontend.app',
'another-app.com',
],
allowedMethods: [
'GET', 'POST'
]
)
);
```