'react axios yafoo finance using http-proxy-middleware happens 504 in china

enter image description here

I want to axios https://query1.finance.yahoo.com/v8/finance/chart/000001.SS to get the date. so i

npm i http-proxy-middleware

and write setupProxy.js under /src.

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/v8',
    createProxyMiddleware({
      target: 'https://query1.finance.yahoo.com',
      changeOrigin: true,
      pathRewrite: {
        '^/v8': '',
      },
    })
  );
};

and in stock.js :

import React, { useEffect,useState } from "react";
import axios from "axios";

const Stocks =  () => {
  const [stockData, setStockData] = useState();
  const [data, setData] = useState([]);
  const fetchStockData = async () => {
    await axios({
      url:'/v8/finance/chart/000001.SS',
      headers:{'content-type':'application/json;charset=utf-8'}
    }).then(res=>{
      setStockData(res.data);
      console.log("stockData",stockData);
    })
  };
  useEffect(() => {
    fetchStockData();
  }, []);

  return <div>Stocks</div>;
};
export default Stocks;

unfortunately , it failed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source