如何在Azure二头肌部署模板中获取Linux App服务的主机URL

发布于 2025-02-13 13:21:10 字数 603 浏览 2 评论 0 原文

我使用下面显示的二头肌资源创建了一个应用程序服务,

  name: '${appName}'
  location: location
  kind: 'linux,container,fnapp'
  properties: {
    serverFarmId: servicePlan.id
    siteConfig: {
      linuxFxVersion: 'DOCKER|${dockerLocation}'
      healthCheckPath: '/api/healthcheck'
      alwaysOn: true
      appSettings: [
        ...
      ]
    }
  }
}

该应用程序可以按预期工作,但是我想获取该应用程序服务的URL,以用作我的APIM服务的后端URL。

我目前正在使用 var fnappurl ='https:// $ {fnapp.name} .azurewebsites.net/api'。有什么办法可以从函数应用程序资源的直接输出中获取默认URL IE var fnappurl = fnapp.url 或类似的东西?

tia

I've created an app service using a bicep resource shown below

  name: '${appName}'
  location: location
  kind: 'linux,container,fnapp'
  properties: {
    serverFarmId: servicePlan.id
    siteConfig: {
      linuxFxVersion: 'DOCKER|${dockerLocation}'
      healthCheckPath: '/api/healthcheck'
      alwaysOn: true
      appSettings: [
        ...
      ]
    }
  }
}

Which works as expected, however I'd like to get the url for that app service to use as a backend url for my apim service.

I'm currently using var fnAppUrl = 'https://${fnApp.name}.azurewebsites.net/api'. Is there any way I can get the default url from the direct output of the function app resource i.e. var fnAppUrl = fnApp.url or something similar?

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤千羽 2025-02-20 13:21:10

通过配置 extensions.http.routeprefix in host.json ,没有针对此基本路径的特定属性。
(文档: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-bindings-http-webhook?tabs=in-process%2cfunctionsv2&pivots; pivots; pivots hostjson-settings

如果/api 前缀是不需要,那么使用二头肌文件中的以下输出就足够了:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
   // ...
}

output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}'

然后在 host.json 中确保将RoutePrefix设置为一个空字符串:

{
    "extensions": {
        "http": {
            "routePrefix": ""
        }
    }
}

如果您想使用路由前缀,您需要将其与默认主机名相结合:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
   // ...
}

output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}/api'

There is no specific property for this base path as it is set by configuring the value of extensions.http.routePrefix in host.json.
(Docs: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook?tabs=in-process%2Cfunctionsv2&pivots=programming-language-csharp#hostjson-settings)

If the /api prefix is not required, then it would suffice to use the following output in your Bicep file:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
   // ...
}

output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}'

Then in your host.json ensure the routePrefix is set to an empty string:

{
    "extensions": {
        "http": {
            "routePrefix": ""
        }
    }
}

If you do want to use a route prefix, you need to combine it with the default host name:

resource myFunctionApp 'Microsoft.Web/sites@2021-03-01' = {
   // ...
}

output functionBaseUrl string = 'https://${myFunctionApp.properties.defaultHostName}/api'
天冷不及心凉 2025-02-20 13:21:10

据我所知,您无法从功能中获得直接URL。但是您可以使用以下内容:

output functionbaseurl string ='https:// $ {function.properties.defaulthostname}/api'

这将导致默认主机名,包括“ azurewebersites.net” part。

template.bicep 中查看完整示例:

As far as I know, there is no direct url you can get from the function. But you can use something like:

output functionBaseUrl string = 'https://${function.properties.defaultHostName}/api'

This will result in the default hostname including the "azurewebsites.net" part.

Check the full example in the template.bicep here:
https://github.com/DSpirit/azure-functions-bicep-outputs-host

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文