Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

Herokuでaxios実行時にhttpでAPIが呼び出されてしまう際の解決策

結論

  • リクエストURLの末尾のスラッシュをつけない
axios.get("/api/hoge?fuga=a")

経緯

axios.get("/api/hoge/?fuga=a")

をHeroku上で実行すると

Mixed Content: The page at 'https://example.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://....js'. This request has been blocked; the content must be served over HTTPS.

がでてAPIを呼び出せない。

【Javascript】Fetch APIのFetch()で予期せぬMixed Content Errorが起きた話
によると、

「リクエストURLの末尾のスラッシュ有無でmixed contentが解消される可能性がある」

とのこと。

axios.get("/api/hoge?fuga=a")

でリクエストURLの末尾のスラッシュをつけない場合は問題なく呼び出せる
Herokuの仕様わからない

参考

【Javascript】Fetch APIのFetch()で予期せぬMixed Content Errorが起きた話

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
3
Help us understand the problem. What are the problem?