diff --git a/src/iisnode/cnodeprocess.cpp b/src/iisnode/cnodeprocess.cpp index b67cf74..0edbc1d 100644 --- a/src/iisnode/cnodeprocess.cpp +++ b/src/iisnode/cnodeprocess.cpp @@ -55,6 +55,10 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) DWORD environmentSize; DWORD flags; HANDLE job; + PWSTR currentDirectory = NULL; + PSTR currentDirectoryA = NULL; + DWORD currentDirectorySize = 0; + DWORD currentDirectorySizeA = 0; RtlZeroMemory(&processInformation, sizeof processInformation); RtlZeroMemory(&startupInfo, sizeof startupInfo); @@ -91,7 +95,6 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) // create the environment block for the node.js process - pass in the named pipe name; // this is a zero terminated list of zero terminated strings of the form = - ErrorIf(NULL == (currentEnvironment = GetEnvironmentStrings()), GetLastError()); environmentSize = 0; do { @@ -104,6 +107,16 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) FreeEnvironmentStrings(currentEnvironment); currentEnvironment = NULL; + // establish the current directory for node.exe process to be the same as the location of the *.js file + + currentDirectory = (PWSTR)context->GetPhysicalPath(¤tDirectorySize); + while (currentDirectorySize && currentDirectory[currentDirectorySize] != L'\\' && currentDirectory[currentDirectorySize] != L'/') + currentDirectorySize--; + ErrorIf(0 == (currentDirectorySizeA = WideCharToMultiByte(CP_ACP, 0, currentDirectory, currentDirectorySize, NULL, 0, NULL, NULL)), E_FAIL); + ErrorIf(NULL == (currentDirectoryA = new char[currentDirectorySize + 1]), ERROR_NOT_ENOUGH_MEMORY); + ErrorIf(currentDirectorySizeA != WideCharToMultiByte(CP_ACP, 0, currentDirectory, currentDirectorySize, currentDirectoryA, currentDirectorySizeA, NULL, NULL), E_FAIL); + currentDirectoryA[currentDirectorySizeA] = '\0'; + // create startup info for the node.js process RtlZeroMemory(&this->startupInfo, sizeof this->startupInfo); @@ -137,7 +150,7 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) TRUE, flags, newEnvironment, - NULL, + currentDirectoryA, &this->startupInfo, &processInformation ), GetLastError()); @@ -189,6 +202,8 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) // clean up + delete [] currentDirectoryA; + currentDirectoryA = NULL; delete [] newEnvironment; newEnvironment = NULL; delete [] fullCommandLine; @@ -199,6 +214,12 @@ HRESULT CNodeProcess::Initialize(IHttpContext* context) return S_OK; Error: + if (currentDirectoryA) + { + delete [] currentDirectoryA; + currentDirectoryA = NULL; + } + if (suuid != NULL) { RpcStringFree(&suuid); diff --git a/src/iisnode/iisnode.vcxproj b/src/iisnode/iisnode.vcxproj index e9b1c40..9e6ddb9 100644 --- a/src/iisnode/iisnode.vcxproj +++ b/src/iisnode/iisnode.vcxproj @@ -229,6 +229,7 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$ + @@ -249,6 +250,9 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$ + + + diff --git a/src/iisnode/iisnode.vcxproj.filters b/src/iisnode/iisnode.vcxproj.filters index bacb296..2eebdb8 100644 --- a/src/iisnode/iisnode.vcxproj.filters +++ b/src/iisnode/iisnode.vcxproj.filters @@ -82,6 +82,9 @@ {f69631ee-6910-4fa3-9e6f-36786970c51e} + + {cc6d4108-5cc9-4576-adf4-6ddc7d186998} + @@ -346,5 +349,17 @@ Config + + Tests\functional\tests + + + Tests\functional\www\107_filesystem + + + Tests\functional\www\107_filesystem + + + Tests\functional\www\107_filesystem + \ No newline at end of file diff --git a/test/functional/tests/107_filesystem.js b/test/functional/tests/107_filesystem.js new file mode 100644 index 0000000..9097c3a --- /dev/null +++ b/test/functional/tests/107_filesystem.js @@ -0,0 +1,9 @@ +/* +Current directory of node.exe process is set to the same location as the applications's *.js file. +*/ + +var iisnodeassert = require("iisnodeassert"); + +iisnodeassert.sequence([ + iisnodeassert.get(10000, "/107_filesystem/hello.js", 200, "Contents of a file") +]); \ No newline at end of file diff --git a/test/functional/www/107_filesystem/file.txt b/test/functional/www/107_filesystem/file.txt new file mode 100644 index 0000000..2c60580 --- /dev/null +++ b/test/functional/www/107_filesystem/file.txt @@ -0,0 +1 @@ +Contents of a file \ No newline at end of file diff --git a/test/functional/www/107_filesystem/hello.js b/test/functional/www/107_filesystem/hello.js new file mode 100644 index 0000000..87fb510 --- /dev/null +++ b/test/functional/www/107_filesystem/hello.js @@ -0,0 +1,10 @@ +var http = require('http'); +var fs = require('fs'); + +http.createServer(function (req, res) { + fs.readFile('file.txt', function (e, d) { + if (e) throw e; + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(d); + }); +}).listen(process.env.PORT); \ No newline at end of file diff --git a/test/functional/www/107_filesystem/web.config b/test/functional/www/107_filesystem/web.config new file mode 100644 index 0000000..ae902f5 --- /dev/null +++ b/test/functional/www/107_filesystem/web.config @@ -0,0 +1,7 @@ + + + + + + +