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
CodePudding user response:
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
CodePudding user response:
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://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook?tabs=in-process,functionsv2&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'