Hello,
i have a local wordpress site and i created an ionic app that must connect to the wordpress site (api) request and display data. but i keep getting access error on console. someone sugested to create a proxy in angular. but i don’t know how to do that.
Use localhost server like Xampp? i build app with WordPress and ionic on localhost work fine. Paste service code here.
thanks for your reply. im using MAMP.
var WooCommerceAPI = require(‘woocommerce-api’);
@Component({
selector: ‘page-about’,
templateUrl: ‘about.html’
})
export class AboutPage {
woocommerce: any;
constructor(public navCtrl: NavController) {
this.woocommerce = WooCommerceAPI({
url: 'http://localhost:8888/wordpress/',
consumerKey: 'ck_79ca76.......',
consumerSecret: 'cs_82466.........'
});
this.woocommerce.getAsync(“products”).then((data)=>{
console.log(“PASSED”);
console.log(JSON.parse(data));
},(err)=>{
console.log(“ERROR”);
console.log(err);
});
}
}
This is the error i get
No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
That’s a CORS error. Have you added proxies for your local/MAMP urls?
e.g. in your ionic.config.json file:
{
"name": "YourAPP",
"app_id": "123456",
"type": "ionic-angular",
"proxies": [
{
"path": "/login",
"proxyUrl": "http://localhost:1234/api_folder/"
}
],
"integrations": {
"cordova": {}
}
}
thanks for your reply. but i still have the same errors even though i made the change you suggested. here is my ionic.config.json file:
{
“name”: “mytabApp”,
“app_id”: “”,
“type”: “ionic-angular”,
“proxies”: [
{
“path”: “/login”,
“proxyUrl”: “http://localhost:8888/wordpress/wc-api/v3/”
}
],
“integrations”: {
“cordova”: {}
}
}
my app run at
try changing
{
“path”: “/login”,
“proxyUrl”: “http://localhost:8888/wordpress/wc-api/v3/”
}
to
{
“path”: “/login”,
“proxyUrl”: “http://localhost:8888/wordpress/wc-api/v3/login”
}
maybe?
i try to change as you suggested still no success