I have CORS set up on my own custom domain for certain routes,
for example https://www.ari-web.xyz/api/apis.json and cors
works fine with it, although on https://ari-web.xyz/api/apis.json
as it’s a redirect it does not follow CORS properly, any way
to make root-level domain respect the headers/CORS rules?
Here’s my netlify.toml part which I want redirects to follow:
(1) Depending on how long this would take, I could revert
my domain to use www again for a bit, although I’m
slightly worried because I don’t want to wait 2 months
again to get back into the HSTS list
(2) Or as @coelmay has said they tested it and it didn’t work,
they might have a setup that is broken (?)
>> fetch("https://www.ari-web.xyz/api/apis.json")
Promise { <state>: "pending" }
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.ari-web.xyz/api/apis.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 301.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.ari-web.xyz/api/apis.json. (Reason: CORS request did not succeed). Status code: (null).
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
>> fetch("https://ari-web.xyz/api/apis.json")
Promise { <state>: "pending" }
Is there a reason you can’t use your primary domain to point these requests at?
Looking at the documentation around this error the proposed solution is to use an URL that does not redirect to a different origin: Reason: CORS request external redirect not allowed - HTTP | MDN
I’m not even sure adding the headers to the redirect would help in any way here.
As a workaround: If you’re requesting this URL from a different Netlify site, you can always put a proxy rule in place to avoid CORS altogether:
The URL does redirect to a different origin, how
CORS works is by validating domain, subdomain, route and
port iirc and the one that changes is the subdomain,
maybe by adding the CORS headers would help? I’m not sure
And I’m not, I want to make it public generally without
needing any proxies nor redicrects, but I guess this is
not solvable from what I understand from this? The user
needs to do it themselves I guess
Anyway, thank you for updating me on this, have a nice
rest of your day