Response to preflight request doesn't pass access control check even though cores is enabled

170 views Asked by At

I am trying to access the Amazon market place api. I get the following error,

Failed to load http://completion.amazon.com/search/complete?search-alias=digital-text&client=amazon-search-ui&fb=1&mkt=1&q=trump: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

But I have passed the headers in AWS rest API also I have enabled cores.

function getAmazonDataByKeyWord(keyword, callback) {
    console.log('dhfajdkh');
    const instance = axios.create({
        baseURL: "http://completion.amazon.com",
        headers: {
            'Access-Control-Allow-Origin': 'http://localhost:9080',
            "Access-Control-Allow-Headers": "Content-Type,Authorization",
            "Access-Control-Allow-Methods": "PUT, GET, POST, DELETE, OPTIONS",
            "Access-Control-Allow-Credentials": true
        },
        xhrFields: {
            withCredentials: false
        }
    });


    instance.defaults.headers["keyId"] = "AKIAI7VIL36475SPDBCA";
    instance.defaults.headers["secretKey"] = "ggyvg0je2oYe84WButOYLIO4qy";
    instance.defaults.headers["asoTag"] = "nerf0e-20";
    instance.defaults.headers["keywordStatsQueue"] = new queue(1, Infinity);
    instance.defaults.headers["keywordStatsAnalyzeQueue"] = new queue(1, Infinity);

    instance.get("/search/complete?search-alias=digital-text&client=amazon-search-ui&fb=1&mkt=1&q=" + keyword).then(function (res) {
        var result = {};
        result.status = httpStatus.OK;
        result.result = res.data;
        console.log('res');
        console.log(result);
        callback(null, result);
    }).catch(function (error) {
        console.log(error);
    });
} 
0

There are 0 answers