This commit is contained in:
Torsten 2024-12-02 09:06:04 +01:00
parent 37924f1187
commit 73a36abe1e
4 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,25 @@
https://www.youtube.com/watch?v=8GhfHZlEaEo&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=41
In case Web Server throws CORS errors when trying to access API.
We add a filter that adds header with CORS info to define which kind of HTTP are allowed from foreign source.
Create CorsFilter.php
```bash
php spark make:filter Cors --suffix
```
Add to before method:
```php
public function before(RequestInterface $request, $arguments=null)
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Authorization, Content-Type, Accept, API-KEY");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH");
}
```
Add in app/Config/Filters.php:
![[Pasted image 20241202084231.png]]
![[Pasted image 20241202084303.png]]

View file

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB