Doubt with API access - using Angular - typescript

0

I set up a website to study a store WooCommerce, I activated the api and generated the keys.

In the root of the site I added in the .htaccess, is it in the correct place?:

# Permite acesso ao pacote Font Awesome
<FilesMatch ".(ttf|otf|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>

More I'm having the error:

Hereisthecompletetestcode:

import{Component}from'@angular/core';import{NavController}from'ionic-angular';import*asWCfrom'woocommerce-api';@Component({selector:'page-home',templateUrl:'home.html'})exportclassHomePage{WooCommerce:any;products:any[];constructor(publicnavCtrl:NavController){this.WooCommerce=WC({url:"http://wooionic.comajudacoletiva.com.br/",
       consumerKey:"ck_899d1c4011cab2bde1f04cd52704c248f155ecdc",
       consumerSecret:"cs_cc90feaf8467c0a53679be89f137557cdc7acbe5"
     });

        this.WooCommerce.getAsync("products").then( (data) => {
          console.log(JSON.parse(data.body));
         // this.products = JSON.parse(data.body).products;
        }, (err) => {
          console.log(err)
        })

  }

}
    
asked by anonymous 08.05.2017 / 18:58

1 answer

1

I believe that being is possible to make it more permissive if it is in a webView (mobile app), but since you have control over the site, just remove FilesMatch , just like that in your .htaccess:

# Permite requisições de qualquer origem
Header set Access-Control-Allow-Origin "*"

Of course this will release any source of access, I recommend you read this excellent response from @mgibsonbr:

Note that if you are using IIS (yes PHP runs on IIS through Fast-CGI or CGI) then you should not use .htaccess and instead create a file named web.config in the root folder of the subdomain instead of a .htaccess , be careful there may already be a web.config , in this case make a backup and edit the original, something like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
       <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>
    
09.05.2017 / 03:19