我正在尝试自动向Azure应用添加自定义域。
这就是我的想法:
customDomain
查询参数触发对Function App的HTTP调用。这是我在功能App中设置的内容:
run.ps1
param($req, $TriggerMetadata)
$customDomain = $req.Query.customDomain
Set-AzWebApp `
-Name some-app `
-ResourceGroupName SouthEastAsia `
-HostNames @($customDomain,"some-app.azurewebsites.net")
Push-OutputBinding -Name res -Value ([HttpResponseContext]@{
StatusCode = [System.Net.HttpStatusCode]::OK
Body = "Added Custom Domain: $customDomain"
})
function.json
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "./run.ps1"
}
但是当我触发HTTP Get请求时,这会给我404 NotFound错误:
https://function.domain/api/AddCustomDomain?customDomain=test
答案 0 :(得分:0)
是否有特定原因将数组传递到-Hostnames
参数中?看来您正在尝试指定默认的Azure主机名,但这不是必需的。
尝试Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames "$customDomain"
如果您确实需要多个自定义域,请尝试将var
括在引号Set-AzWebApp -Name some-app -ResourceGroupName SouthEastAsia -HostNames @("$customDomain1","$customDomain2","$customDomain3")
中