Closed lpj145 closed 7 years ago
I've got a similar trouble with CakePHP 3.4.
First of all, i've had to create the Application.php (see https://book.cakephp.org/3.0/en/controllers/middleware.html#using-middleware and https://book.cakephp.org/3.0/en/controllers/middleware.html#adding-http-stack).
But then, i've got new errors i.e. "->is() is not longer an available method" and has to be checked with getMethod() === "OPTIONS"...
Could you share what you wrote in your application.php and index.php ? I seem to have the same problem...
I've run into same problem. It is still not solved?
I'm suffering from the same problem:
`2017-08-07 11:13:59 Error: [Error] Call to undefined method Zend\Diactoros\ServerRequest::is() Stack Trace:
The problem is this: (from ozee31\cakephp-cors\Routing\Middleware\CorsMiddleware.php)
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) {
if ($request->getHeader('Origin')) {
$response = $response
->withHeader('Access-Control-Allow-Origin', $this->_allowOrigin($request))
->withHeader('Access-Control-Allow-Credentials', $this->_allowCredentials())
->withHeader('Access-Control-Max-Age', $this->_maxAge());
if ($request->is('options')) {
$response = $response
->withHeader('Access-Control-Allow-Headers', $this->_allowHeaders($request))
->withHeader('Access-Control-Allow-Methods', $this->_allowMethods())
->withHeader('Access-Control-Expose-Headers', $this->_exposeHeaders());
return $response;
}
}
return $next($request, $response);
}
The $request->is('options') tries to call a method #is() on what is thought to be an instance of Zend\Diactoros\ServerRequest. I'm still running CakePHP 3.3(.16), so I don't think this issue was only introduced on CakePHP 3.4.
Does anyone know a solution to this?
EDIT: I have worked around my problem ("#is() is not a valid method for the request") by reverting this plugin from v1.1.0 to v1.0.2.
It's fixed
Thank you @munvier
new cake 3.4 Cors not work, on normal execution, Allow-Control-Access-Origin not set yet.