boonej-zz / site-metadata-parser

1 stars 1 forks source link

Cross Origin Request error. How to set mode to no-cors? #1

Closed niranjanshankar closed 7 years ago

niranjanshankar commented 7 years ago

For some sites I could retrieve metadata but obviously for others I could not. Here's my code:

constructor(){
    new Scraper({
        host: 'https://en.wikipedia.org/wiki/Main_Page',
        path: '/',
    }).scrape(function(err, data) {
        console.log("scraped data:")
        console.log(data);
    });
}

Error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

How to set the mode to no-cors? Any help would be appreciated.

boonej-zz commented 7 years ago

CORS is unrelated to your issue. Try moving "/wiki/Main_Page" to the path option. The response test in spec has been reworked to use the wikipedia example in the 0.2 branch.