2个使用Axios的API调用,都显示在本地服务器中-但只有一个显示为已部署

时间:2019-12-26 22:33:12

标签: reactjs api axios

我在React with Axios中进行了2次API调用。在我的本地服务器中,两个调用均出现,在部署到Netify之后,仅出现第一个API调用。我不知道是什么原因造成的,因为我没有错误消息。 右图是部署后的图像,左图是本地服务器上的图像。我将密钥XXX了,所以它没有出现在代码中

enter image description here

import axios from 'axios';

const API_URL = 'https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=XXXX';
const API_URL2= 'http://newsapi.org/v2/top-headlines?sources=ars-technica&apiKey=XXXX';

export const getNews = async () => {
  const result = await axios.get(API_URL)
  .then(response => {
  return response.data.articles;
  });
  return(result);
}

export const getNews2 = async () => {
  const result = await axios.get(API_URL2)
  .then(response => {
  console.log(response.data)
  return response.data.articles;
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });
  return(result);

1 个答案:

答案 0 :(得分:2)

为什么第一个是https,第二个是http?