Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at

motorcb
Member | 552
+
0
-

Hello,
I have simple API in Nette. That is OK.
When I want to call the API from React, is there Error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xxx.com/api/v1/users. (Reason: CORS request did not succeed). Status code: (null).

How to fix it?
Thanx

David Grudl
Nette Core | 8218
+
-3
-

Do you know Google?

motorcb
Member | 552
+
+1
-

David Grudl wrote:

Do you know Google?

I can :-) But I don't know how to write it in Nette …

	header("Access-Control-Allow-Origin: *");
	header("Access-Control-Allow-Methods: PUT, GET, POST");
	header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
dakur
Member | 493
+
+1
-

I'd say something like $this->getHttpResponse()->addHeader('Access-Control-Allow-Origin, '*') in presenter..

See Response object for more on working with headers.

Last edited by dakur (2022-09-08 08:51)

David Grudl
Nette Core | 8218
+
0
-

motorcb wrote:

I can :-) But I don't know how to write it in Nette …

https://www.google.com/search?…

motorcb
Member | 552
+
0
-

Thanks guys