Aditya
Aditya

Reputation: 817

How to access APIs that don't allow cors?

I want to use an API (that doesn't support CORs) in my NodeJS app.

Actually it's not really an API. A site uses that link to get the data.

I have downloaded a browser extension which lets me access the API. Is there any way I can access it in my NodeJS app, like by tweaking the Http header?

I use request module to send request.

var request = require('request');

var options = {
    url: 'http://kalimatimarket.gov.np/priceinfo/dlypricebulletin',
    method: 'POST',
    data : "cdate=07/01/2017&pricetype=R"
    // do something to allow cors
};

request(options, (err, res, body)=> {
    console.log(body)
});

Without and with CORS enabled

Upvotes: 0

Views: 744

Answers (1)

vahdet
vahdet

Reputation: 6729

  • Either set Allow-Control-Allow-Origin on the server site indicating the client url, or
  • Use jsonp

Upvotes: 1

Related Questions