From ce3bbbb295d02de56981cc77ac056d4fdb0ebef9 Mon Sep 17 00:00:00 2001 From: Markavian Date: Fri, 7 Sep 2018 22:22:39 +0200 Subject: [PATCH 1/4] Accept opts.server value in engine.js In order to provide values such as REQUEST_URI from express to the PHPExpress engine. --- lib/PHPExpress/engine.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/PHPExpress/engine.js b/lib/PHPExpress/engine.js index d0846a8..45f04f9 100644 --- a/lib/PHPExpress/engine.js +++ b/lib/PHPExpress/engine.js @@ -14,11 +14,13 @@ var engine = function (filePath, opts, callback) { query = opts.query || querystring.stringify(get), body = opts.body || querystring.stringify(post), + server = querystring.stringify(opts.server || {}) env = { REQUEST_METHOD: method, CONTENT_LENGTH: body.length, - QUERY_STRING: query + QUERY_STRING: query, + SERVER: server }; var command = util.format( From 9b3095920f08b6fb9dfb3cb5d11adad4c892ecd6 Mon Sep 17 00:00:00 2001 From: John Beech Date: Fri, 7 Sep 2018 22:34:02 +0200 Subject: [PATCH 2/4] Allow additional environment variables to be set using opts.server --- lib/PHPExpress/engine.js | 7 +++++-- lib/PHPExpress/router.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/PHPExpress/engine.js b/lib/PHPExpress/engine.js index 45f04f9..83dfce2 100644 --- a/lib/PHPExpress/engine.js +++ b/lib/PHPExpress/engine.js @@ -14,15 +14,18 @@ var engine = function (filePath, opts, callback) { query = opts.query || querystring.stringify(get), body = opts.body || querystring.stringify(post), - server = querystring.stringify(opts.server || {}) + server = opts.server || {}, env = { REQUEST_METHOD: method, CONTENT_LENGTH: body.length, QUERY_STRING: query, - SERVER: server }; + server.forEach(key => { + env[key] = server[key] + }); + var command = util.format( '%s %s %s %s', (body ? util.format('echo "%s" | ', body) : '') + binPath, diff --git a/lib/PHPExpress/router.js b/lib/PHPExpress/router.js index 90e4d7e..e1e7e82 100644 --- a/lib/PHPExpress/router.js +++ b/lib/PHPExpress/router.js @@ -2,6 +2,9 @@ module.exports = function(req, res) { res.render(req.path.slice(1), { method: req.method, get: req.query, - post: req.body + post: req.body, + server: { + REQUEST_URI: req.url + } }); -}; \ No newline at end of file +}; From 01672440164c9979c67efbe1c14ff6a30b344342 Mon Sep 17 00:00:00 2001 From: John Beech Date: Fri, 7 Sep 2018 22:52:25 +0200 Subject: [PATCH 3/4] Correctly map keys to environment variables --- lib/PHPExpress/engine.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PHPExpress/engine.js b/lib/PHPExpress/engine.js index 83dfce2..536c76d 100644 --- a/lib/PHPExpress/engine.js +++ b/lib/PHPExpress/engine.js @@ -22,7 +22,7 @@ var engine = function (filePath, opts, callback) { QUERY_STRING: query, }; - server.forEach(key => { + Object.keys(server).forEach(key => { env[key] = server[key] }); From e77fc19ea2df38cbfaf278fe48007bef35a3ac0c Mon Sep 17 00:00:00 2001 From: John Beech Date: Tue, 2 Jun 2020 15:38:24 +0100 Subject: [PATCH 4/4] Fix Undefined Index REQUEST_METHOD and lint file --- page_runner.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/page_runner.php b/page_runner.php index 1568c0c..43c8f53 100644 --- a/page_runner.php +++ b/page_runner.php @@ -1,15 +1,22 @@ 0)) - { - parse_str(fread(STDIN, $_SERVER['CONTENT_LENGTH']), $_POST); - } +//parse the standard input into the $_POST variable +if (($REQUEST_METHOD === 'POST') + && ($CONTENT_LENGTH > 0) +) { + parse_str(fread(STDIN, $CONTENT_LENGTH), $_POST); +} - chdir($argv[1]); - require_once $argv[2]; +chdir($argv[1]); +require_once $argv[2];