754 B
754 B
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
php spark make:filter Cors --suffix
Add to before method:
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");
}

