rmrn11
rmrn11

Reputation: 1

Can Javascript access an external or localhost database or nodejs?

I'm using a javascript scripting engine for a MUD i'm playing, they have a javascript client hosted on their server. I'm wanting to store some information in a database and access it from the client (or inject it somehow into the client) but I'm not seeing how I could do that.

Basically I can write javascript files into the trigger section of the website and they fire. It has Javascript and JQuery options. It does not have a database option on their end, which is why I'm trying to add it myself.

I know client side javascript has a lot of restrictions on it, so I'm not sure how far I could really go with this.

Upvotes: 0

Views: 85

Answers (1)

ferhtgoldaraz
ferhtgoldaraz

Reputation: 1843

I think you might be able to do this, but it's going to be hacky.

If you're able to attach a script node to the dom, you can trigger GET requests with no origin restrictions wherever you want. You would do that to your own backend.

You would have to throw away all good practices and use GET requests with a lot of query params so send data to that (your) backend.

You would have to write the backend so that it does whatever you want with the data, e.g. store it in the db.

You would have to make sure you return valid js to the client, even if it's only to dismiss it.

Alternatively...

you could load an iframe to a site you control, and change the iframe src with the data, and then do with the data whatever you want (like sending it to some bakcend of yours properly) in your site (that's loaded in the iframe) by detecting changes in the url...

Upvotes: 1

Related Questions