e621ng / e621ng

e621.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API endpoint e621.net/posts.json cannot give response because of CORS

Materia597 opened this issue · comments

Using JavaScript's fetch with the e621 API on the "e621.net/posts.json" endpoint never returns a response with a body, as either an error is thrown related to CORS policy, or the response is opaque.

If I use the code fetch("https://e621.net/posts.json?tags=____"), (where ____ can be any tag string),the error

Access to 'https://www.e621.net/posts.json?tags=____' from origin 'https://127.0.0.1:5501' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

Including user credential, authorization, caching, or any other header does not remove this issue or similar issues related to the CORS policy.

If the mode: 'no-cors' header is added, then a response is successfully returned, however the return object is opaque without a body.

This has not always been an issue, since code from July 2023 that used the code fetch("https://e621.net/posts.json?tags=____", {cache: 'no-cache'}) functioned properly, but it now throws the error shown above.

Has the CORS policy on the e621 servers been changed recently? And if so would it be possible to correct this change to allow API calls to access this endpoint? Currently there is no way to fetch this endpoint.

You are accessing the website under the www subdomain. This redirects and is not allowed under CORS. Please just make the request without the subdomain and it should work.