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
2
Answers
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
There is no specific property for this base path as it is set by configuring the value of
extensions.http.routePrefix
inhost.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:Then in your
host.json
ensure the routePrefix is set to an empty string:If you do want to use a route prefix, you need to combine it with the default host name: