LoginSignup
0

More than 5 years have passed since last update.

API Managementで管理しているAPIを外部から実行すると失敗する時の対処法

Posted at

API Managementで管理されたAPIの実行が失敗

Azure FunctionsでAPIを作成し、API Management上のテストでは成功したのですが、
Azure BLOBからAPI Managementで管理されたAPIを実行すると、以下のエラーが出ました。

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<BLOB URL>' is therefore not allowed access.

理由を調べたところクロスドメインの制限がかかっているから、
CORSの設定が必要みたいです。

詳しい解説は下記の動画が勉強になります。(英語ですが)

API Management でのCORSの設定方法

AzureポータルからAPI Management→「API」タブ→作成したAPI→「デザイン」タブの順に進みます。
下記の図のように、Inbound processingの右上の三角をクリックし、「Code editor」を開きます。

api_edit.png

CORSを<inbound>タグに追加し、allow-credentialsをfalseにします。

add_cors.png

制限をかける場合は適宜*を置き換えてください。
後は設定を保存すれば、無事にAPIの実行ができます。

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