新搭建Nuxt3应用启动时报Nitro代理错误:proxyReq.appendHeader is not a function
Nuxt3 启动报错:proxyReq.appendHeader is not a function
长期使用Nuxt2,近期尝试搭建Nuxt3应用。按照官方安装文档完成部署后,启动本地服务器时出现如下错误:
ERROR [uncaughtException] proxyReq.appendHeader is not a function
该错误与Nuxt使用的Nitro引擎相关,堆栈信息如下:
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
内容的提问来源于stack exchange,提问作者Paul Carlson
相关产品推荐
相关产品推荐

