生产 React 应用程序因 429 错误而失败

时间:2021-04-24 16:40:04

标签: node.js reactjs nginx amazon-ec2 http-status-code-429

我已经建立了一个反应应用程序网页,我使用节点,表达和反应。我在带有 nginx 的 ec2 ubuntu 服务器中提供服务,我还安装了 ssl 并配置了 DNS,但是当我加载页面时,第一次没有问题,但是当重新加载时,我得到了这个 Server responded with 429 status code< /p>

页面本身非常简单,但仍然失败,我无法解决问题,我阅读了很多帖子和博客来修复它,但没有一个有效(这只发生在生产环境中,在开发环境中我得到运行我的节点应用程序时没有错误)。

有些人说你必须延迟加载图像,我做到了,我也尝试过超时加载组​​件,因此每 1.5 秒发出一次请求...

给我带来问题的主要文件是 ma​​nifest.jsonfavicon.ico,它们可以通过 url 访问,所以我不明白为什么({{3 }}).

节点 server.js

<块引用>

路由什么都没有,只有控制台日志

require('dotenv').config();
const express = require("express");
const app = express();
const path = require("path");
const cors = require("cors");

const allowedOrigins = [`http://localhost:${process.env.PORT}`];

var corsOptions = {
  origin: function (origin, callback) {
    if (allowedOrigins.indexOf(origin) !== -1 || !origin) {
      callback(null, true)
    } else {
      callback(new Error('Not allowed by CORS'))
    }
  }
};

app.use(cors(corsOptions));

app.use(express.urlencoded({ extended: false }));
app.use(express.json());

app.use(express.static(path.join(__dirname, "/public")));

app.use("/", require("./routes/routes"));
app.get("*", (_, res) => res.redirect("/"))

app.listen(process.env.PORT, function () {
  console.log(`Listening on port ${process.env.PORT}`);
});

应用目录结构

another 429 example,public 文件夹是 react 脚本 npm run build 返回的构建。

React 应用目录结构

This is my folders structure,运行 npx create-react-app 时得到的结果没有什么特别之处。如您所见,有一个 favicon.icomanifest.json

Manifest.json

{
  "short_name": "Proximedica Bajío",
  "name": "Proximedica Bajío - Oxígeno Medicinal",
  "icons": [
    {
      "src": "favicon.ico",
      "sizes": "64x64 32x32 24x24 16x16",
      "type": "image/x-icon"
    },
    {
      "src": "logo192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "logo512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

这就是全部,如果您需要我提供一些其他文件,那将是一种乐趣。 谢谢!

0 个答案:

没有答案
相关问题