...
This commit is contained in:
parent
37924f1187
commit
73a36abe1e
4 changed files with 25 additions and 0 deletions
|
|
@ -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]]
|
||||
|
Before Width: | Height: | Size: 150 KiB After Width: | Height: | Size: 150 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241202084231.png
Normal file
BIN
MyObsidianVault/_images/Pasted image 20241202084231.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 257 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241202084303.png
Normal file
BIN
MyObsidianVault/_images/Pasted image 20241202084303.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 317 KiB |
Loading…
Add table
Add a link
Reference in a new issue