Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ntukey opened this issue Apr 28, 2024 · 1 comment
Open

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

ntukey opened this issue Apr 28, 2024 · 1 comment

Comments

@ntukey
Copy link

ntukey commented Apr 28, 2024

(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.

@ntukey ntukey changed the title javascript で CORS policy のエラーが出る JavaScript で CORS policy のエラーが出る Apr 29, 2024
@hotate29
Copy link
Contributor

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

pub(crate) async fn get_language_list(
_request: HttpRequest,
pool: web::Data<PgPool>,
) -> Result<HttpResponse> {
let languages = pool
.load_languages()
.await
.map_err(error::ErrorInternalServerError)?;
let response = HttpResponse::Ok().json(&languages);
Ok(response)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants