-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doubled up the filepaths in Windows #125
Comments
The issue seems to be here: file = file[0] === '/' ? file : path.join(pathname || '.', file); Both |
The issue is reproducible using Node 0.10 as well, I've updated the issue report. Weirdly enough, downgrading to the current stable release (0.7.3), |
@phstc as @UltCombo mentioned the issue lies in node-static/lib/node-static.js Line 296 in 4220671
pathname to key (which, if pathname is null, becomes file[0] ) in 3bdf0d7 .
As far as I understand
checks if file is absolute but the check holds only on UNIXes. |
Thanks for the quick bug tracking @mrfabbri! As for the absolute paths checking, we should be able to use one of the answers in this topic. Peoro's answer seems to be more robust yet still simple. |
@mrfabbri awesome bug tracking. 🍻
Isn't the key == pathname? key = pathname || files[0] cc/ @IonicaBizau |
I'm not a Windows user, but I can recommend you to check if the issue existed before my change: $ git clone [email protected]:cloudhead/node-static.git
$ cd node-static
$ git reset --hard 4858a8212c580fa831b9614825275f38791df579
$ npm install
$ npm test Also, the tests are passing on Ubuntu 14.04 (using the current release): ionicabizau@laptop:~/node-static$ npm test
> [email protected] test /home/ionicabizau/node-static
> vows --spec --isolate
♢ node-static
once an http server is listening with a callback
✓ should be listening
streaming a 404 page
✓ should respond with 404
✓ should respond with the streamed content
once an http server is listening without a callback
✓ should be listening
requesting a file not found
✓ should respond with 404
requesting a malformed URI
✓ should respond with 400
serving hello.txt
✓ should respond with 200
✓ should respond with text/plain
✓ should respond with hello world
serving directory index
✓ should respond with 200
✓ should respond with text/html
serving index.html from the cache
✓ should respond with 200
✓ should respond with text/html
requesting with If-None-Match
✓ should respond with 304
requesting with If-None-Match and If-Modified-Since
✓ should respond with a 200
requesting POST
✓ should respond with 200
✓ should not be empty
requesting HEAD
✓ should respond with 200
✓ head must has no body
requesting headers
✓ should respond with node-static/0.7.3
addings custom mime types
✓ should add woff
serving subdirectory index
✓ should respond with 200
✓ should respond with text/html
redirecting to subdirectory index
✓ should respond with 301
✓ should respond with location header
✓ should respond with empty string body
requesting a subdirectory (with trailing slash) not found
✓ should respond with 404
requesting a subdirectory (without trailing slash) not found
✓ should respond with 404
✓ OK » 28 honored (0.151s) |
@IonicaBizau the commit |
@IonicaBizau tests result on Windows 7 for commit 7f655b1 are not passing (tests on previous commit 4c64f0c are passing, also tests 4858a82
|
I installed Windows 7 in my VBox. The tests fail when using Cannot reproduce the issue with serving var static = require('node-static');
// var Path = require("path");
// var file = new static.Server(Path.join(process.cwd(), 'public'), { cache: 7200, headers: {'X-Hello':'World!'} });
var file = new static.Server('./public', { cache: 7200, headers: {'X-Hello':'World!'} });
require('http').createServer(function (request, response) {
file.serve(request, response, function (err, res) {
if (err) {
console.error("> Error serving " + request.url + " - " + err.message);
response.writeHead(err.status, err.headers);
response.end();
} else {
console.log("> " + request.url + " - " + res.message);
}
});
}).listen(8080);
console.log("> node-static is listening on http://127.0.0.1:8080"); The file is correctly served in both cases. Relevant output: C:\Users\John\Documents\node-static [master +1 ~1 -0 !]> npm test
> [email protected] test C:\Users\John\Documents\node-static
> vows --spec --isolate
? node-static
once an http server is listening with a callback
√ should be listening
streaming a 404 page
√ should respond with 404
√ should respond with the streamed content
once an http server is listening without a callback
√ should be listening
requesting a file not found
√ should respond with 404
requesting a malformed URI
√ should respond with 400
serving hello.txt
√ should respond with 200
√ should respond with text/plain
√ should respond with hello world
serving directory index
√ should respond with 200
√ should respond with text/html
serving index.html from the cache
√ should respond with 200
√ should respond with text/html
requesting with If-None-Match
√ should respond with 304
requesting with If-None-Match and If-Modified-Since
√ -should respond with a 200
requesting POST
√ should respond with 200
√ should not be empty
requesting HEAD
√ should respond with 200
√ head must has no body
requesting headers
√ should respond with node-static/0.7.3
addings custom mime types
√ should add woff
serving subdirectory index
√ should respond with 200
√ should respond with text/html
redirecting to subdirectory index
√ should respond with 301
√ should respond with location header
√ should respond with empty string body
requesting a subdirectory (with trailing slash) not found
√ should respond with 404
? Errored » 1 errored (0.000s)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
C:\Users\John\Documents\node-static [master +1 ~1 -0 !]>
C:\Users\John\Documents\node-static [master +1 ~1 -0 !]> git diff
diff --git a/lib/node-static.js b/lib/node-static.js
index ebb748b..d40eac5 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -269,8 +269,8 @@ Server.prototype.respondNoGzip = function (pathname, status,
finish(304, headers);
} else {
res.writeHead(status, headers);
-
- this.stream(key, files, new(buffer.Buffer)(stat.size), res, function (e
+ debugger
+ this.stream(pathname, files, new(buffer.Buffer)(stat.size), res, functi
if (e) { return finish(500, {}) }
finish(status, headers);
});
C:\Users\John\Documents\node-static [master +1 ~1 -0 !]> git checkout .
C:\Users\John\Documents\node-static [master +1 ~0 -0 !]> npm test
> [email protected] test C:\Users\John\Documents\node-static
> vows --spec --isolate
? node-static
once an http server is listening with a callback
√ should be listening
streaming a 404 page
√ should respond with 404
√ should respond with the streamed content
once an http server is listening without a callback
√ should be listening
requesting a file not found
√ should respond with 404
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\hello.
txt\C:\Users\John\Documents\node-static\test\fixtures\hello.txt']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\hello.txt\\C:\
\Users\\John\\Documents\\node-static\\test\\fixtures\\hello.txt' }
requesting a malformed URI
√ should respond with 400
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
serving hello.txt
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:104
? should respond with text/plain
» expected .,
got undefined (==) // node-static-test.js:107
? should respond with hello world
»
actual expected
hello world
// node-static-test.js:110
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
serving directory index
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:119
? should respond with text/html
» expected .,
got undefined (==) // node-static-test.js:122
serving index.html from the cache
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:131
? should respond with text/html
» expected .,
got undefined (==) // node-static-test.js:134
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
requesting with If-None-Match
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
? should respond with 304
» expected 304,
got 500 (==) // node-static-test.js:151
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
requesting with If-None-Match and If-Modified-Since
? should respond with a 200
» expected 200,
got 500 (==) // node-static-test.js:173
| requesting POST
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:183
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
? should not be empty
» expected . to be not empty // node-static-test.js:186
requesting HEAD
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:196
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\index.
html\C:\Users\John\Documents\node-static\test\fixtures\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html\\C:
\\Users\\John\\Documents\\node-static\\test\\fixtures\\index.html' }
√ head must has no body
requesting headers
√ should respond with node-static/0.7.3
addings custom mime types
√ should add woff
{ [Error: ENOENT, open 'C:\Users\John\Documents\node-static\test\fixtures\there\
index.html\C:\Users\John\Documents\node-static\test\fixtures\there\index.html']
errno: 34,
code: 'ENOENT',
path: 'C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\there\\index.h
tml\\C:\\Users\\John\\Documents\\node-static\\test\\fixtures\\there\\index.html'
}
serving subdirectory index
? should respond with 200
» expected 200,
got 500 (==) // node-static-test.js:221
? should respond with text/html
» expected ..,
got undefined (==) // node-static-test.js:224
redirecting to subdirectory index
√ should respond with 301
√ should respond with location header
√ should respond with empty string body
requesting a subdirectory (with trailing slash) not found
√ should respond with 404
? Errored » 1 errored (0.000s)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0 |
@UltCombo Can you provide a zip file containing the project that reproduces the issue? |
Then open |
Note that although I'm using an absolute path -- |
Yes, seems that |
I added a little fix for checking if path is absolute. Is it enough? See pull request #126. |
Test case
Project root is at
C:\tests\node-static-test
.Creating a
new static.Server()
passing'./public'
,'public'
orpath.join(process.cwd(), 'public')
results in this error when requesting/hello.html
:These tests are against the latest commit (beb25d3) in this repository, by the way.
The text was updated successfully, but these errors were encountered: