Access repl's DB from repl's webview

I’m trying to write to my (html/js/css) repl’s db as part of it’s website using:

let xhr = new XMLHttpRequest();
xhr.open("POST", <DB URL>, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(<DATA>));

however I am being blocked by CORS, with the error:

Access to XMLHttpRequest at from origin has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I’ve seen some people suggesting using cors-anywhere but I’d rather fix the problem the “intended” way, by setting the correct header on the server. However I don’t know how to do this, or even if it is possible to.

I’ve tried making a similar request using curl, which worked fine, and I’ve tried querrying a database from a different repl instead of the host repl, which gave me the same error. So I think the problem is cuased by making a post request from a repl-hosted website.

If there isn’t a solution to this I could made my program as a desktop app, but this complicates other things, so I’d like to keep it a website if possible.

You will need a server-side language, like NodeJS, to interact with ReplDB. I’ve tried using vanilla JavaScript before, but even if you could, it would be much more insecure as you’d have to expose your ReplDB URL.

3 Likes

Since my site only needs to be used by myself and my friend, I was thinking of giving him the key and making the website store it in localStorage. But since it sounds like a website wont work anyway I think I’ll just make it in TKinter. Thanks for the help

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