API Management ではPolicyを使ってCORSの設定を行う。
CORSの設定は、API単位でも設定可能だが、Operation単位でも設定可能。
以下、Operationに追加する場合のXML例。
<policies>
<inbound>
<cors allow-credentials="false">
<allowed-origins>
<origin>https://sample1.com</origin>
<origin>https://sample2.com</origin>
<origin>https://sample3.com</origin>
<origin>https://sample4.com</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
全てのクライアントに対して許可する場合は次の通り。
<policies>
<inbound>
<cors allow-credentials="false">
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
注意点
-
<cors>
の後に<base />
を書く必要がある。