CORS Annoying Problem

I was doing a data transfer test for backend storage. I created two websites, “Test” (https://replit.com/@OSoft/test?v=1) and “Recieve” (https://replit.com/@OSoft/Receive?v=1). The test website allows me to type in data, and then send it to “Recieve”. Once “Recieve” receives data, that data is stored to data.txt. But whenever I press “send”, nothing happens, and the console says this:
Screen Shot 2023-05-13 at 12.29.20 AM
.
So I put the “neccesary” CORS headers inside of my script.js file in the Recieve website, and made the script run when the website is loaded, but I still get the same error for CORS. My recieve website explicitly allows test.osoft.repl.co’s requests. Why is this happening?

I don’t see any problem.

Then why isn’t any data being transferred, and why are there CORS errors?

If there are CORS errors, I can’t see them.

(Sorry, I’m really not that good at CORS)

Uh, I literally sent a screenshot of the error.

Ok, well, sorry, I don’t know that much about cors (sry)

Hi @OSoft!
Let me get straight to the point. Why do you have node.js code in a front-end repl? That’s not… good. Consider making a Node.js repl instead for the (“Recieve”) repl (as it’s supposed to serve a back-end purpose).
Secondly, you don’t actually set the Access-Control-Allow-Origin header. You can do this with the <meta> tag, however if you actually want to recieve post data, use a backend, like Node.js which I have mentioned before.

Hope this helps, and cheers!

2 Likes

Yeah, as @NoNameByProgram was saying, require is a part of NodeJS, which is not the same JavaScript which runs in your browser.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.