No ‘Access-Control-Allow-Origin’ header is present
-
Hi,
I am using this plugin for my React.js application for user registrations / authentications, however I am getting a
No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
error every time when I am trying to authenticate a user. (This error is not present when I am calling the “built-in” endpoints of the rest api, like fetching posts / comments etc. )
My wordpress back end is located on https://api.my-site.com
any my front end is on https://my-site.comI am getting the same error in both cases when I try to authenticate the user from localhost:3000, and from my-site.com
Error:
Access to XMLHttpRequest at 'https://api.my-site.com/api/user/generate_auth_cookie/?nonce=0d852f970e&username=username&password=password' from origin 'https://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I already added to my .htaccess file in the folder where the wordpress backend is:
<IfModule mod_headers.c> <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$"> Header set Access-Control-Allow-Origin "*" </FilesMatch> </IfModule>
I also tried to add some headers to the index.php file:
<?php header ("Access-Control-Allow-Origin: *"); header ("Access-Control-Expose-Headers: Content-Length, X-JSON"); header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS"); header ("Access-Control-Allow-Headers: *");
This drives me crazy… could you please help me?
Thanking in advance!
- The topic ‘No ‘Access-Control-Allow-Origin’ header is present’ is closed to new replies.