LoginSignup
0
1

Azure API Management Service での CORS設定

Posted at

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 /> を書く必要がある。
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1