我正在尝试使用本地测试 Netlify 的 lambda 函数netlify-lambda
,但无法让代理与 Gatsbyjs 一起使用。我一直在控制台中收到这个:
[HPM] Rewriting path from "/.netlify/functions/add-subscriber" to "/add-subscriber"
[HPM] GET /.netlify/functions/add-subscriber ~> http://localhost:9000
[HPM] Error occurred while trying to proxy request /add-subscriber from localhost:8000 to http://localhost:9000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
这就是我在请求中得到的
尝试代理时出错:localhost:8000/add-subscriber
这就是我gatsby-config.js
文件中的内容
developMiddleware: app => {
app.use(
"/.netlify/functions",
proxy({
target: "http://localhost:9000",
pathRewrite: {
"^/\\.netlify/functions": ""
},
logLevel: "debug"
})
)
}
这就是我提出请求的地方
onSubmit(values) {
fetch('/.netlify/functions/add-subscriber')
.then(resp => resp.json())
.then(resp => console.log(resp))
.catch(e => {
console.error(e)
})
}
我尝试了几个例子,但没有一个对我有用。我还关闭了所有可能使用这些端口的程序。从浏览器测试 URL ( http://localhost:9000/add-subscriber ) 工作正常。直接获取 URL 也可以正常工作。问题可能是什么?