Azure CORS 变量允许的来源
Azure CORS Variable Allowed Origins
每当 Azure DevOps 中的新发布管道 运行 时,URL 就会更改。目前我的 ARM 模板有一个硬编码的 URL,保留起来可能很烦人关于手动添加。
"cors": {
"allowedOrigins": [
"[concat('https://',parameters('storage_account_name'),'.z10.web.core.windows.net')]"
}
唯一改变的是 z10
中的 10
部分所以基本上我希望它是这样的
[concat('https://',parameters('storage_account_name'),'.z', '*', '.web.core.windows.net')]
我不知道这样的东西是否有效,但本质上是这样,因此 cors 策略将接受 URL 而不管 z 编号。
基本上来说这是不可能的,因为 CORS 标准 (see docs)。
仅允许确切来源、通配符或空值。
例如,用于 Azure 存储的 ARM 也遵循这种模式,允许您放置确切来源列表或通配符 (see ARM docs)
但是,如果您知道您的 网站 名称,在您的 ARM 中您可以接收完整的主机并在您的 CORS 中使用它:
"[reference(resourceId('Microsoft.Web/sites', parameters('SiteName')), '2018-02-01').defaultHostName]"
与静态网站相同(我猜这是你的情况)如果你知道存储帐户名称:
"[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2019-06-01', 'Full').properties.primaryEndpoints.web]"
高级参考输出操作
回答评论 - 如果您想替换 reference
函数输出中的某些字符,最简单的方法是使用内置替换函数 (see docs)
如果您需要更高级的方案,我将通过引入一个自定义函数来粘贴我的解决方案,该函数从末尾删除 https://
和 /
,因此 https://contonso.com/
转换为 contonso.com
:
"functions": [
{
"namespace": "lmc",
"members": {
"replaceUri": {
"parameters": [
{
"name": "uriString",
"type": "string"
}
],
"output": {
"type": "string",
"value": "[replace(replace(parameters('uriString'), 'https://',''), '/','')]"
}
}
}
}
],
# ...(some code)...
"resources": [
# ... (some resource)...:
"properties": {
"hostName": "[lmc.replaceUri(reference(variables('storageNameCdn')).primaryEndpoints.blob)]"
}
]
每当 Azure DevOps 中的新发布管道 运行 时,URL 就会更改。目前我的 ARM 模板有一个硬编码的 URL,保留起来可能很烦人关于手动添加。
"cors": {
"allowedOrigins": [
"[concat('https://',parameters('storage_account_name'),'.z10.web.core.windows.net')]"
}
唯一改变的是 z10
中的 10
部分所以基本上我希望它是这样的
[concat('https://',parameters('storage_account_name'),'.z', '*', '.web.core.windows.net')]
我不知道这样的东西是否有效,但本质上是这样,因此 cors 策略将接受 URL 而不管 z 编号。
基本上来说这是不可能的,因为 CORS 标准 (see docs)。 仅允许确切来源、通配符或空值。
例如,用于 Azure 存储的 ARM 也遵循这种模式,允许您放置确切来源列表或通配符 (see ARM docs)
但是,如果您知道您的 网站 名称,在您的 ARM 中您可以接收完整的主机并在您的 CORS 中使用它:
"[reference(resourceId('Microsoft.Web/sites', parameters('SiteName')), '2018-02-01').defaultHostName]"
与静态网站相同(我猜这是你的情况)如果你知道存储帐户名称:
"[reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2019-06-01', 'Full').properties.primaryEndpoints.web]"
高级参考输出操作
回答评论 - 如果您想替换 reference
函数输出中的某些字符,最简单的方法是使用内置替换函数 (see docs)
如果您需要更高级的方案,我将通过引入一个自定义函数来粘贴我的解决方案,该函数从末尾删除 https://
和 /
,因此 https://contonso.com/
转换为 contonso.com
:
"functions": [
{
"namespace": "lmc",
"members": {
"replaceUri": {
"parameters": [
{
"name": "uriString",
"type": "string"
}
],
"output": {
"type": "string",
"value": "[replace(replace(parameters('uriString'), 'https://',''), '/','')]"
}
}
}
}
],
# ...(some code)...
"resources": [
# ... (some resource)...:
"properties": {
"hostName": "[lmc.replaceUri(reference(variables('storageNameCdn')).primaryEndpoints.blob)]"
}
]