r/shittyprogramming • • Dec 06 '17

Server-side JavaScript code?

Hi I'm trying to make Server-sided JavaScript code. Can Someone help me?

4 Upvotes

16 comments sorted by

View all comments

11

u/skylarmt Dec 06 '17 edited Dec 06 '17

It's quite simple. Start with a regular Apache/PHP install, then install Java on the server. Upload a JavaScript file that generates your HTML and stores it in a var. Next write some Java code that reads your JavaScript file and executes it with javax.script.ScriptEngine. Dump the contents of your var from ScriptEngine with System.out.println(). Now in your index.php, write:

<?php
$site = `java -jar MySite.jar`;
echo $site;

If you want an extra layer of security, run the jar file from a Python script and change your PHP to use python MySite.py instead.