【发布时间】:2018-07-31 05:16:11
【问题描述】:
我正在尝试使用 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 也可以正常工作。可能是什么问题?
【问题讨论】:
标签: node.js webpack gatsby netlify http-proxy-middleware