本地主机上的 Azure Functions 代理 404
Azure Functions Proxy 404 on localhost
我有一个 Azure Function App,在 URL http://localhost:7072/api/create-room
有一个函数以及其他函数。此特定函数是一个 HTTPTrigger
允许匿名访问并接受 GET
动词:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")]
除此之外,我还有一个单独的函数应用程序,它仅托管一个 proxies.json
文件并且仅用作函数代理。我的代理功能是 运行ning 在本地端口 7071
上。
我的代理文件目前看起来像这样:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"chatNegotiate": {
"matchCondition": {
"route": "/api/chat/negotiate",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/BeginNegotiate"
},
"chatMessages": {
"matchCondition": {
"route": "/api/chat/messages",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/PostMessage"
},
"createRoom": {
"matchCondition": {
"route": "/api/create-room",
"methods": [
"GET"
]
},
"backendUri": "%session_api%/api/CreateRoom"
}
}
}
当这两个功能应用程序都部署到 Azure 时,一切都像梦一样。我可以提出请求,他们被转发,请求回来。都是光荣的。
但是,当我在本地 运行 这些功能时,请求永远不会从代理转发,代理返回 404。我可以在另一个功能应用程序上点击该功能 运行直接在本地 7072
上,那里一切都很好,但当我通过代理服务器时完全没有。
代理本身returns:
[30/05/2020 18:24:30] Host lock lease acquired by instance ID '0000000000000000000000002D5B6BEA'.
[30/05/2020 18:24:34] Executing HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room"
[30/05/2020 18:24:34] }
[30/05/2020 18:24:34] Executed HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room",
[30/05/2020 18:24:34] "identities": [],
[30/05/2020 18:24:34] "status": 404,
[30/05/2020 18:24:34] "duration": 15
[30/05/2020 18:24:34] }
根据我看过的示例,例如 https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/,这应该可以正常工作。
有什么建议吗?提前感谢您提供的任何帮助!
我终于解决了这个问题
proxies.json默认没有设置复制到输出目录。
您需要确保将其设置为始终复制。
在Visual Studio中:
右键单击 proxies.json
> 单击 属性 > 将 复制到输出目录 设置为 始终复制 .
在Visual Studio代码(和其他编辑)中:
打开 ProjectName.csproj
并添加一个条目以始终将 proxies.json
复制到输出目录。
<ItemGroup>
<None Update="proxies.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
这解决了我本地函数应用程序代理实例上的 404 问题。在 local.settings.json 中将此添加到值:
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": 正确,
来源:https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/
我有一个 Azure Function App,在 URL http://localhost:7072/api/create-room
有一个函数以及其他函数。此特定函数是一个 HTTPTrigger
允许匿名访问并接受 GET
动词:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")]
除此之外,我还有一个单独的函数应用程序,它仅托管一个 proxies.json
文件并且仅用作函数代理。我的代理功能是 运行ning 在本地端口 7071
上。
我的代理文件目前看起来像这样:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"chatNegotiate": {
"matchCondition": {
"route": "/api/chat/negotiate",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/BeginNegotiate"
},
"chatMessages": {
"matchCondition": {
"route": "/api/chat/messages",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/PostMessage"
},
"createRoom": {
"matchCondition": {
"route": "/api/create-room",
"methods": [
"GET"
]
},
"backendUri": "%session_api%/api/CreateRoom"
}
}
}
当这两个功能应用程序都部署到 Azure 时,一切都像梦一样。我可以提出请求,他们被转发,请求回来。都是光荣的。
但是,当我在本地 运行 这些功能时,请求永远不会从代理转发,代理返回 404。我可以在另一个功能应用程序上点击该功能 运行直接在本地 7072
上,那里一切都很好,但当我通过代理服务器时完全没有。
代理本身returns:
[30/05/2020 18:24:30] Host lock lease acquired by instance ID '0000000000000000000000002D5B6BEA'.
[30/05/2020 18:24:34] Executing HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room"
[30/05/2020 18:24:34] }
[30/05/2020 18:24:34] Executed HTTP request: {
[30/05/2020 18:24:34] "requestId": "9004b8e2-f208-4a98-8b48-6f85bca41281",
[30/05/2020 18:24:34] "method": "GET",
[30/05/2020 18:24:34] "uri": "/api/create-room",
[30/05/2020 18:24:34] "identities": [],
[30/05/2020 18:24:34] "status": 404,
[30/05/2020 18:24:34] "duration": 15
[30/05/2020 18:24:34] }
根据我看过的示例,例如 https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/,这应该可以正常工作。
有什么建议吗?提前感谢您提供的任何帮助!
我终于解决了这个问题
proxies.json默认没有设置复制到输出目录。
您需要确保将其设置为始终复制。
在Visual Studio中:
右键单击 proxies.json
> 单击 属性 > 将 复制到输出目录 设置为 始终复制 .
在Visual Studio代码(和其他编辑)中:
打开 ProjectName.csproj
并添加一个条目以始终将 proxies.json
复制到输出目录。
<ItemGroup>
<None Update="proxies.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
这解决了我本地函数应用程序代理实例上的 404 问题。在 local.settings.json 中将此添加到值:
"AZURE_FUNCTION_PROXY_DISABLE_LOCAL_CALL": 正确,
来源:https://chsakell.com/2019/02/03/azure-functions-proxies-in-action/