-
Notifications
You must be signed in to change notification settings - Fork 30
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
how to solve cors. #61
Comments
I think this may require a change to monero core, but I'd have to re-test this myself. |
Hi, any updates with CORS? Facing the same problem |
No updates - could you provide a minimal test suite? Presumably in Javascript ? |
To connect to the LWS API from websites with a different domain/IP address than the one where LWS is located, you need to include the "Access-Control-Allow-Origin" header in the response from the LWS server. Its value can be set to "*" to allow connections from any domain and IP address, or it can be set to the specific domain/IP address the user wants to grant access to. If this header is absent, browsers will display an error message in the console: "Access to resource has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource" (e.g., in Chrome). |
Hi VTNerd- This is still an issue. Save this as an html file, update the main address, secret view key and the LWS url and open it in your browser and click the button. There will be a CORS error in the console and network tab. If you use a CORS disable extension for your browser, you'll see that the request succeeds. <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>LWS Fetch API POST Request Example</title>
</head>
<body>
<button id="lwsButton">Make LWS POST Request</button>
<script>
const myButton = document.getElementById("lwsButton");
myButton.addEventListener("click", async () => {
const url = "http://localhost:8000/get_address_txs";
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
address: "yourMainAddressHere",
view_key: "yourSecretViewKeyHere",
}),
};
try {
const response = await fetch(url, options);
const responseData = await response.json();
console.log(responseData);
} catch (error) {
console.error(error);
}
});
</script>
</body>
</html> |
And CORS seems to work fine with Monerod (setting the access control config option). There are a number of 'browser compatible' nodes: https://monero.fail/?chain=monero&network=mainnet&cors=on .. There just seems to be something funky with LWS and CORS config. I have never been able to get it to work and have to proxy all of my calls. |
LWS is using the same CORS code as |
I'm running with I don't have any issues with local stuff - my flask app is able to hit LWS without issue and JS on web pages is as well. @CryptoGrampy 's sample code actually works for me - CORS is not an issue with simple ajax request. In @TechGoku 's example, I'm guessing they are running mymonero-web-js (because of port 9110 being bound). If that is indeed the case, the issue is with the |
Access to XMLHttpRequest at 'http://127.0.0.1:8443/login' from origin 'http://127.0.0.1:9110' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
index.js:98 ❌ Error: Connection Failure
i have added --access-control-origin http://127.0.0.1:9110 . while running lws daemon . but still i am facing this issue .
The text was updated successfully, but these errors were encountered: