Express 正在使用 curl 但不在 React 网站上

Express is working with curl but not on react website

我正在尝试做一个利用 React 前端和 Express 后端的简单网站。现在,反应网站已成功托管在我购买的域上。在同一台机器上,有一个快递服务器运行。我可以用 curl http://localhost:3000/api 成功调用它。我已将代码添加到响应前端以 console.log api 端点的结果。控制台向我显示来自网站的 404 错误。请帮助我了解我配置错误的地方。

我已将行 "proxy": "http://localhost:3000", 添加到 package.json 文件。

前端

import React, { useEffect} from 'react';
import './App.css';

function App() {
  fetch('api')
  .then(res => {
      console.log(res);
   })

  return (
    <div className="App">
      <header className="App-header">
        <p>
          Site Under Construction
        </p>
      </header>
    </div>
  );
  
}

export default App;

后端

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

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


// create a GET route
app.get('/api', (req, res) => { //Line 9
  res.send({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' }); //Line 10
}); //Line 11

我在我的 nginx 文件中添加了以下反向代理,它似乎已经解决了这个问题。

         location /api/ {    # Backend
              proxy_pass  http://localhost:3001;
         }