woocommerce / wc-api-node

This client is obsolete and will no longer receive updates, a new JavaScript library is available under the name of @woocommerce/woocommerce-rest-api
https://www.npmjs.com/package/woocommerce-api
MIT License
144 stars 63 forks source link

origin blocked by CORS #97

Closed sauravcd02 closed 5 years ago

sauravcd02 commented 5 years ago

i am trying to test ionic app on browser with wc-api-node. it show me origin blocked by CORS issue. i have add proxies still same issue capture.

kbehov commented 5 years ago

Add this code to youre functions.php --> function add_cors_http_header(){ header("Access-Control-Allow-Origin: *"); header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS, READ'); header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token,authorization,XMLHttpRequest, user-agent, accept'); header("Access-Control-Allow-Credentials: true");

if ( 'OPTIONS' == $_SERVER['REQUEST_METHOD'] ) {
    status_header(200);
    exit();
}

} add_action('init','add_cors_http_header');

sauravcd02 commented 5 years ago

Thnak you for your quick response. I have used the above code, in my thems/functions.php file but i have found this errors.

capture 1

kbehov commented 5 years ago

Change header("Access-Control-Allow-Origin: *"); to header("Access-Control-Allow-Origin: http://localhost:8100");

rowellfortune commented 5 years ago

Thanks this worked

kbehov commented 5 years ago

Happy to hear that!

claudiosanches commented 5 years ago

This library is now deprecated, you should try https://github.com/woocommerce/woocommerce-rest-api-js-lib