十二个 REST API 在移动浏览器上不起作用?

Twelve REST API doesn't work on mobile browsers?

我已经将站点部署到 Netlify (https://quizzical-nightingale-64ead9.netlify.app/) and I use a node server to make an axios request to the Twelve API (https://rapidapi.com/twelvedata/api/twelve-data1)

API 仅供参考,每分钟有 12 个请求的限制。

它在我的桌面上 Chrome 上运行良好,但在任何移动浏览器上都无法运行(brave、duckduckgo、Chrome)。

我不认为它是 Twelve 特有的,因为我在 Finnhub API 上也有过类似的经历。我认为这与它是一个移动浏览器这一事实有关。也许是 CORS?

这是我的 server/index.js 文件。

const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const axios = require('axios').default;
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;

app.use(express.json({ limit: '1mb' }));

app.listen(port, () => console.log(`Listening on port ${port}`));

const options = {
  method: 'GET',
  url: 'https://twelve-data1.p.rapidapi.com/price',
  params: { symbol: 'GME', format: 'json', outputsize: '30' },
  headers: {
    'x-rapidapi-host': 'twelve-data1.p.rapidapi.com',
    'x-rapidapi-key': process.env.TWELVE_API_KEY,
  },
};

app.get('/gme_quote', (req, res) => {
  axios
    .request(options)
    .then(function (response) {
      const price = response.data.price;
      res.send(price);
    })
    .catch(function (error) {
      console.error(error);
    });
});

这是我的反应组件

import { useState, useEffect } from 'react';
import axios from 'axios';

export default function GameStop() {
  const [price, setPrice] = useState(0);
  useEffect(() => {
    axios
      .get('http://localhost:5000/gme_quote')
      .then((response) => {
        let price = response.data.toFixed(2);
        setPrice(price);
      })
      .catch((err) => console.log(err));
  }, []);

  return (
    <div className="flex flex-col items-center">
      <h1 className="text-red-500 text-6xl font-black">GME</h1>
      <h1 className="text-white text-7xl md:text-8xl mt-10 md:mt-20">
        ${price}
      </h1>
    </div>
  );
}

我已经在我的移动设备 (safari) 上检查过了,它对我来说工作得很好。

Twelve Data API 的速率限制为每分钟 8 个请求,每天总共 800 个请求。可能是您达到了速率限制,这就是它无法正常工作的原因。