Azure函数非常棒。我正在寻找关于设置Azure函数、处理多个网页(如webApp )和/或在Azure函数中托管webApp的最佳方法的指导/建议。
在Amazon Lambda/ AI网关中,我可以拥有AI。网关将多个请求URL路由到相同的lambda函数,但我不知道如何使用Azure函数来实现这一点。
例如,如果我有一个azure函数设置为:http://hostname/myfunc,如果我可以设置它,那么如果一个用户进入http://hostname/myfunc/home,我的azure函数仍然会被调用,并且我的函数可以基于它自己的路由逻辑来处理。
我尝试使多个代理指向相同的Azure函数,但没有将代理url作为请求信息的一部分
作为一种变通方法,我可以为每个http Url使用一个单独的Azure函数,但这似乎有点夸大其词。
发布于 2017-04-13 12:27:06
Azure Function Proxies应该能够帮助你。
假设您有一个azure函数,其中包含以下URL https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1?name=alice
如果您还希望使用https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1/home?name=alice调用此函数
您可以创建代理。这个代理看起来像这样。
如果您想让其他路由指向相同的函数,只需添加更多代理即可。
您的proxies.json将如下所示
{
"proxies": {
"proxy1": {
"matchCondition": {
"route": "/api/HttpTriggerCSharp1/home"
},
"backendUri": "https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1"
},
"proxy2": {
"matchCondition": {
"route": "/home"
},
"backendUri": "https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1"
}
}
}
这样,您的函数现在也可以调用为:https://testfunctionproxies.azurewebsites.net/home?name=alice
如果你需要在你的函数中识别路由,你可以向你的后端传递一个查询字符串参数来识别原始路径。
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"proxy1": {
"matchCondition": {
"route": "/api/HttpTriggerCSharp1/home"
},
"backendUri": "https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1",
"requestOverrides": {
"backend.request.querystring.originalPath": "/api/HttpTriggerCSharp1/home"
}
},
"proxy2": {
"matchCondition": {
"route": "/home"
},
"backendUri": "https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1?origninalPath=home",
"requestOverrides": {
"backend.request.querystring.originalPath": "/home"
}
}
}
}
现在,如果调用https://testfunctionproxies.azurewebsites.net/home?name=alice,还会给出原始路径
https://stackoverflow.com/questions/43383210
复制相似问题