-
Notifications
You must be signed in to change notification settings - Fork 9
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
CORS error when using from frontend #108
Comments
Hi @makmonty! Thanks for reporting this issue. There must be something strange going on. I just created a new React app as a test, and I am indeed able to make API calls through the library with client-side JS: Here's my very minimal source code: import { buildAuthorization, getUserProfile } from "./index";
function App() {
const username = "WCopeland";
const webApiKey = "redacted";
const authorization = buildAuthorization({ username, webApiKey });
const handleButtonClick = async () => {
const userProfile = await getUserProfile(authorization, {
username: "xelnia",
});
console.log(userProfile);
};
return <button onClick={handleButtonClick}>make api call</button>;
}
export default App; However, it's worth noting that I'm not seeing a preflight Is it possible your Vue app is injecting anything into the HTTP call? Custom headers, etc? Any sort of "interference" like this will likely trigger a preflight request. |
I tried your code and it didn't work for me. BUT, I tried to run both your code and mine on Chrome and both worked fine. As you said, on Chrome the preflight call doesn't happen, but it does on Firefox. |
I ran into the same issue with Firefox and Safari. The API requests fail due to CORS errors, but everything works fine in Chrome. This issue occurs in both localhost and live preview environments. FIREFOX: OPTIONS /API/API_GetUserProfile.php?z=User-Agent: Mozilla/5.0 |
I get a CORS error (preflight OPTIONS request fails) when I try to use the library from a frontend app.
I created a minimal setup project here https://github.com/makmonty/ra-bug-min-rep
Note: I don't get the error if I do the same requests with my own implementation as such:
So it's not a configuration issue at the API side.
My environment is:
Browser: Firefox 131.0
SO: Arch Linux
The text was updated successfully, but these errors were encountered: