首页 > 解决方案 > 快速/节点获取的套接字挂起错误

问题描述

根据 CloudFlare Analytics,在过去的几个小时内,我的网站收到了超过 30 万个请求。在此期间,我遇到了阻止我的网站加载 (DDoS) 的错误。

我一直收到这个错误,我一生都无法弄清楚如何解决这个问题......

错误:

FetchError: request to https://api.discordbots.co/v1/get/bots failed, reason: socket hang up

这是 /v1/get/bots 端点代码:

this.router.get("/v1/get/bots", (req: Request, res: Response, next) => {
    if (!this.isAuthorized(req)) return res.status(401).send({
        error: true,
        response: "Invalid authorization key."
    });

    return res.status(200).send({
        error: false,
        response: this.client.botUpdater.bots
    });
});

编辑:我正在从 nextjs 应用程序发出请求,如下所示:

export async function getServerSideProps(context) {
  const response: Response = await fetch(`${process.env.API}/v1/get/bots`, {
    headers: {
      "Authorization": process.env.AUTHORIZATION as string
    }
  });
  const result = await response.json();

  return { props: { bots: result.response ? result.response : null, error: result.error, loading: false } }
}

如果有人可以为此提供可行的解决方案,我将不胜感激,这压力太大了。

标签: javascriptnode.jsexpresssockets

解决方案


推荐阅读