本文介绍了AzureFunctions作为WebApp指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure功能很棒.我正在寻找有关设置Azure功能以处理多个网页(例如webApp)和/或在Azure功能内部托管webApp的最佳方法的指导/建议.

在Amazon Lambda/AI.Gateway中,我可以使用AI.网关将多个请求URL路由到同一个lambda函数,但我看不到如何使用Azure函数来完成此任务.

例如,如果我将azure函数设置为:

如果您希望其他路线指向同一功能,只需添加更多代理即可.

您的proxies.json看起来像这样

  {代理":{"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",代理":{"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还会为您提供原始路径

Azure functions are awesome. I'm looking for guidance/suggestions on best way to setup an Azure function handle multiple web pages like a webApp and/or host a webApp inside of an Azure function.

In an Amazon Lambda/AI.Gateway I can have the AI. gateway route multiple requests URL to the same lambda function but I don't see how to accomplish this with Azure functions.

Example if I have an azure function setup to: http://hostname/myfunc it be great if I could set it up so if a user entered http://hostname/myfunc/home my azure function would still be invoked and my function could handle based on its own routing logic.

I tried making multiple proxies point to the same Azure function but I don't get the proxy url as part of the request information

As a workaround I can have a separate Azure function for each http Url but this seems a little overkill.

解决方案

Azure Function Proxies should be able to help you.

Lets say you have a azure function with the following URLhttps://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1?name=alice

If you want this function to also be called with https://testfunctionproxies.azurewebsites.net/api/HttpTriggerCSharp1/home?name=alice

You can create a Proxy. This proxy will look something like this.

If you want to have other routes point to the same function, simply add more proxies.

Your proxies.json would look something like this

{
"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"
    }
}

}

With this your function can now also be called as:https://testfunctionproxies.azurewebsites.net/home?name=alice

If you need to identify the routes in your function, you could pass an query string parameter to you backend identify what was the original path.

{
   "$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"
            }
        }
    }
}

Now if you call https://testfunctionproxies.azurewebsites.net/home?name=alicewill also give you the original path

这篇关于AzureFunctions作为WebApp指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 01:47