新的 Nuxt3 应用程序抛出与 Nitro 代理相关的未定义错误

问题描述 投票:0回答:1

我已经在 Nuxt2 上工作了一段时间,所以我想我应该尝试一下 3。完成此处找到的安装说明后:https://nuxt.com/docs/getting-started/installation运行本地服务器时出现以下错误:

 ERROR  [uncaughtException] proxyReq.appendHeader is not a function
。 它似乎与 Nuxt 使用的硝基引擎有关:

  at ProxyServer.<anonymous> (/C:/Users/cards/Documents/job-hunt/job-site/node_modules/nitropack/dist/chunks/server.mjs:329:18)
  at ProxyServer.emit (node:events:527:28)
  at ClientRequest.<anonymous> (/C:/Users/cards/Documents/job-hunt/job-site/node_modules/httpxy/dist/index.mjs:256:16)
  at ClientRequest.emit (node:events:527:28)
  at tickOnSocket (node:_http_client:764:7)
  at onSocketNT (node:_http_client:827:5)
  at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

我希望如果我做了任何改变,我可能会破坏一些东西,但这些错误从一开始就是正确的。我做了一些研究,但没有发现任何与此类似的问题。

导致我出现问题的代码部分是:

proxy.proxy.on("proxyReq", (proxyReq, req) => {
    if (!proxyReq.hasHeader("x-forwarded-for")) {
      const address = req.socket.remoteAddress;
      if (address) {
        proxyReq.appendHeader("x-forwarded-for", address);
      }
    }
    if (!proxyReq.hasHeader("x-forwarded-port")) {
      const localPort = req?.socket?.localPort;
      if (localPort) {
        proxyReq.setHeader("x-forwarded-port", req.socket.localPort);
      }
    }
    if (!proxyReq.hasHeader("x-forwarded-Proto")) {
      const encrypted = req?.connection?.encrypted;
      proxyReq.setHeader("x-forwarded-proto", encrypted ? "https" : "http");
    }
  });

从那里错误的确切行:

proxyReq.appendHeader("x-forwarded-for", address);

我正在使用 Nuxt 版本:3.10.3 和 Nitro 2.9.1

node.js vuejs3 nuxt.js nuxtjs3
1个回答
0
投票

cnpm i [电子邮件受保护]
这样就可以解决问题了

© www.soinside.com 2019 - 2024. All rights reserved.