From ca680a7f6d63ca97913a50018305db4659a34f2f Mon Sep 17 00:00:00 2001 From: Craig Phillips Date: Mon, 23 Feb 2015 11:28:58 +0000 Subject: [PATCH 1/2] Fix hard-coded windows paths. --- README.md | 1 + src/CgiNodeConfig.js | 2 +- src/build.js | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3362a87..c0a36d6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ CGI-Node run on shared hosting sites running Apache. It can run along side PHP. Action cgi-node /cgi-bin/cgi-node.js AddHandler cgi-node .jss +
  • Ensure you set the CGI_NODE_SESSIONDIR environment variable on your Apache instance
  • That's it! diff --git a/src/CgiNodeConfig.js b/src/CgiNodeConfig.js index 12ef20d..1963928 100644 --- a/src/CgiNodeConfig.js +++ b/src/CgiNodeConfig.js @@ -41,5 +41,5 @@ var CgiNodeConfig = SessionCookie: 'CGI-NODE-SESSIONID', SessionTimeOut: 15*60, // 15 minutes - SessionPath: 'D:/Programs/nodejs/sessions/' + SessionPath: process.env.CGI_NODE_SESSIONDIR || 'D:/Programs/nodejs/sessions/' }; diff --git a/src/build.js b/src/build.js index da7c76d..5f96ccb 100644 --- a/src/build.js +++ b/src/build.js @@ -145,15 +145,30 @@ var HTTP = require('http'); var QueryString = require('querystring'); // Specifies the path to where node executable exists. NOTE: windows machines require the double quotes. -var nodeExecPathLinux = '/usr/bin/nodejs' +var nodeExecPathLinux = '/usr/bin/env node'; var nodeExecPathWindows = '"D:/Programs/nodejs/node.exe"'; +var nodeExecPath; // The list of files to build in the correct order. -var files = ['CgiNodeConfig.js', 'CgiNodeContext.js', 'CgiNodeSession.js', 'CgiNodeResponse.js', 'CgiNodeRequest.js', 'CgiNodeParser.js', 'CgiNode.js']; +var files = [ + 'CgiNodeConfig.js', + 'CgiNodeContext.js', + 'CgiNodeSession.js', + 'CgiNodeResponse.js', + 'CgiNodeRequest.js', + 'CgiNodeParser.js', + 'CgiNode.js' + ]; + +if (FS.existsSync(nodeExecPathLinux)) { + nodeExecPath = nodeExecPathLinux; +} else { + nodeExecPath = nodeExecPathWindows; +} // The output path and file name. var output = '../cgi-bin/cgi-node'; // Create the build class and run it. var build = new CgiNodeBuilder(); -build.run(files, output, nodeExecPathWindows); +build.run(files, output, nodeExecPath); From e78623720e3998932a64be58583207db14941821 Mon Sep 17 00:00:00 2001 From: Craig Phillips Date: Mon, 23 Feb 2015 11:38:47 +0000 Subject: [PATCH 2/2] Ensure the session directory is created. --- src/CgiNodeSession.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CgiNodeSession.js b/src/CgiNodeSession.js index 8493b35..51f69b8 100644 --- a/src/CgiNodeSession.js +++ b/src/CgiNodeSession.js @@ -73,6 +73,11 @@ function CgiHttpSession(request, response) this.id = (request.cookies.hasOwnProperty(CgiNodeConfig.SessionCookie) ? request.cookies[CgiNodeConfig.SessionCookie] : this.create()); var path = Path.join(CgiNodeConfig.SessionPath, this.id); + // If the path doesn't exist, then create it. + if (! FS.existsSync(CgiNodeConfig.SessionPath)) { + FS.mkdirSync(CgiNodeConfig.SessionPath, 0700); + } + // If the file does not exist then create another ID. if (!FS.existsSync(path)) this.id = this.create();