A
A
Aleksandr19_932019-02-06 22:25:45
API
Aleksandr19_93, 2019-02-06 22:25:45

Problems requesting API Vue CLI?

Here is the api.js Vue CLI code, what is wrong with it?

import rp from 'request-promise';

const requestOptions = {
method: 'GET',
uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest',
qs: {
start : 1,
limit: 5,
convert: 'USD'
},
headers: {
'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c',
'Access-Control-Allow-Origin': '*'
 },
json: true
};

rp(requestOptions).then(response => {
const result = response.data;
}).catch((err) => {
err.message;
});

When trying to access the coinmarketcap API, it gives the following errors:
1. OPTIONS https://pro-аpi.coinmarketcap.com/v1/cryptocurrenc... 500
2. Access to fetch at ' https://pro-api. coinmarketcap.com/v1/cryptocurrenc... ' from origin ' localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Konyukhov, 2019-02-12
@heahoh

What is not clear - the error message is indicated - CORS
How to deal with it - server settings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question