No 'Access-Control-Allow-Origin' when call rest API

I am using ReactJs with WordPress. WordPress running on localhost 8888 port and React app running on 3000 port. When I change the WordPress site URL (from settings->general) to localhost:300 then I am getting the following error,

Access to XMLHttpRequest at 'http://localhost:8888/bolb/wp-json/wp/v2/categories' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It's not working on the postman too. But, it's okay if I use the same URL (http://localhost:8888/bolb) as the site URL.

Topic wp-api rest-api Wordpress

Category Web


just write this on your function.php

add_filter( 'allowed_http_origin', '__return_true' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.