Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http=require("http"),fs=require("fs"),exec=require("child_process").exec;
- var server=http.createServer((req,res)=> {
- console.log(req.method,req.url);
- if(req.url=="/") req.url="/index.php";
- if(req.method=="GET") {
- if(req.url.match(/\/.+\.php.*/)&&fs.existsSync("scripts/"+req.url)) {
- console.log("OK",fs.readdirSync("scripts"));
- exec("./php.exe scripts"+req.url, (error,stdout,stderr) => {
- if(error) console.log("error:",error);
- console.log("sending "+req.url+" to user");
- res.writeHead(200,{"Content-Type":"text/html"});
- res.end(stdout);
- });
- } else {
- console.log("script",req.url,"not found");
- res.writeHead(303,{"Location":"/"}); //303 redirection
- res.end();
- }
- } else if(req.method=="POST") {
- //POST handling impossible :(
- var data="";
- req.on("data",(chunk)=>data+=chunk);
- req.on("end",()=>{
- console.log("got data",data);
- fs.writeFileSync("php_latestData.tmp",data);
- res.writeHead(303,{"Location":req.url});
- res.end();
- });
- } else if(req.method=="OPTIONS") {
- //enable CORS
- res.writeHead(200,
- {"Access-Control-Allow-Methods":"GET,OPTIONS",
- "Access-Control-Allow-Origin":"*"});
- res.end();
- } else {
- res.writeHead(400);
- res.end();
- }
- }).listen(719); //uses PHP 7.1.9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement