kenkoooo / AtCoderProblems

Extend your AtCoder
https://kenkoooo.com/atcoder/
MIT License
1.39k stars 150 forks source link

JavaScript で CORS policy のエラーが出る #1471

Open ntukey opened 2 months ago

ntukey commented 2 months ago
(async () => {
    const url = "https://kenkoooo.com/atcoder/atcoder-api/v3/language_list";
    const option = { method: "GET", mode: "cors", cache: "force-cache" };
    const res = await fetch(url, option);
    const text = await res.text();
    console.log(text);
  })();

上記のようなスクリプトを atcoder.jp 上で実行すると、次のようなエラーが出て、 ファイルの取得ができないのですが、解決する方法があれば教えていただけませんか

Access to fetch at 'https://kenkoooo.com/atcoder/atcoder-api/v3/language_list' from origin 'https://atcoder.jp' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

hotate29 commented 2 months ago

バックエンド側でのCORSの設定を忘れていそう(.make_cors()が付いていてほしい)

https://github.com/kenkoooo/AtCoderProblems/blob/37e64781e37e7b0332cc8fe54e99d38ff0229d3e/atcoder-problems-backend/src/server/language_count.rs#L4-L14