0

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.

Mark Romano
  • 701
  • 3
  • 12
  • 25
  • 3
    _"Anyone know of a library that can take care of this?"_ Careful, such requests are off-topic for SO. Perhaps instead you can share your attempts so that the community can then help to fix? – James Thorpe May 19 '17 at 14:49
  • eval is evil. => somebody could takeover your server. *its just a personal project* => still not a reason to write unsecure code... – Jonas Wilms May 19 '17 at 14:51
  • Mark, have you tried reloading the script like this? http://stackoverflow.com/questions/9642205/how-to-force-a-script-reload-and-re-execute @Jonasw, If someone can take over your server by writing client-side js, then you have bigger problems... – posit labs May 19 '17 at 17:53
  • @positlabs *client side* ??? Hes talking about evaling users js on server side... – Jonas Wilms May 19 '17 at 17:53
  • Ah, ok i get it now. He should use docker or something :). There is also https://npm.runkit.com/karma but I'm not really familiar with it. – posit labs May 19 '17 at 17:58

0 Answers0