Friday 19 May 2017

Processing user input as javascript backend

I'm trying to build a "codewars" like clone. I want an HTML page with an input form that a client writes their solution in. When they hit submit, a post request is sent to my server with the string in the request body. I then want to evaluate that string as code on my server, run some test cases on it, and serve back the results.

eval() is of course the first solution that comes to mind, and since this is a personal project that doesn't need to be secure, it would be a great option. Only thing is, I'm have alot of trouble using eval() on the request body object property of interest. It will evaluate the function like expected, but I can't call that function later in my code - it's not saved in the execution context, and if I try to invoke it , I error out.

I came up with some hacky solutions, but they're not very reliable. Anyone know of a library that can take care of this? Or some other kind of method of sending their string to my server that will somehow work with eval?

Thank you.



via Mark Romano

No comments:

Post a Comment