gpt4 book ai didi

azure - 我可以在 Azure 静态 Web 应用程序中使用通配符进行重定向吗?

转载 作者:行者123 更新时间:2023-12-02 05:56:22 25 4
gpt4 key购买 nike

我正在尝试将 API 调用从我的静态 Web 应用程序重定向到另一个函数应用程序,但我无法使用通配符。

路线匹配正确,但我希望将 * 部分包含在重定向中。这是我的 staticwebapp.config.json

中的示例
  {
"route": "/api/client/*",
"redirect": "https://xx.yy.net/api/client/*"
}

我希望请求 /api/client/customer/get?customerId=xx 变为 https://xx.yy.net/api/client/customer/get? customerId=xx.

但无论我尝试什么,它都只能很难路由到我在重定向中放入的内容。通过函数,这可以通过代理实现,但我在静态 Web 应用程序中找不到方法。

最佳答案

有点晚了,但就我而言,可以从 header 中获取原始 URL:

        if (shortUrl == "*")
{
var original = req.Headers
.FirstOrDefault(h => h.Key.ToLower() == "x-ms-original-url")
.Value.FirstOrDefault()?.ToString();
if (string.IsNullOrWhiteSpace(original))
{
shortUrl = "";
}
else
{
shortUrl = original.Split("/")
.Where(p => !string.IsNullOrWhiteSpace(p))?
.LastOrDefault() ??"";
}
}

关于azure - 我可以在 Azure 静态 Web 应用程序中使用通配符进行重定向吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67022988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com