Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix cli interface for Node 0.10 #86

Closed
wants to merge 2 commits into from

5 participants

@edpaget

I will also update tests and docs (one test is failing at the moment, that I'm trying to trouble shoot), but it's a one line change to add request.resume() to the cli server. Mostly I wanted to get this up, so people who upgrade to 0.10 don't need to be confused about why the static command stopped working like I was.

@deiga

:+1: for this one. Had me stumped for a while

@phstc
Collaborator

Hey!

I tested and the tests npm test seems to be passing fine. Which test is failing for you?

Is request.resume() obligatory in Node 0.10?

http://nodejs.org/api/http.html#http_message_resume

Resumes a paused request/response.

I didn't get it.

@deiga

I had the problem of node-static not running an endless loop in my browser, adding request.resume() fixed this. So yeah, it seems obligatory

@jflasher

Awesome, thanks, ran in to this one as well as I first tried this on 0.10!

@edpaget

@phstc this test fails for me on OS X 10.7.

streaming a 404 page
    ✗ should respond with 404
      TypeError: Cannot read property 'statusCode' of undefined
      at Request.suite.addBatch.addBatch.streaming a 404 page.should respond with 404 (/Users/edpaget/Documents/node-static/test/integration/node-static-test.js:50:30)
      at runTest (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows.js:132:26)
      at EventEmitter.<anonymous> (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows.js:85:17)
      at EventEmitter.emit (events.js:117:20)
      at EventEmitter.options.Emitter.emit (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows.js:237:24)
      at that.emitter.ctx (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows/context.js:31:52)
      at Request.env.callback [as _callback] (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows/context.js:46:29)
      at self.callback (/Users/edpaget/Documents/node-static/node_modules/request/index.js:142:22)
      at Request.EventEmitter.emit (events.js:95:17)
      at Request.options.Emitter.emit (/Users/edpaget/Documents/node-static/node_modules/vows/lib/vows.js:237:24)
    ✗ should respond with the streamed content
        » expected 'Custom 404 Stream.',
        got      undefined (==) // node-static-test.js:54
@edpaget

@phstc request.resume() isn't obligatory in Node 0.10. The new Streams2 api pauses streams if there isn't a listener for a 'data' event. Since the static command only listens for an 'end' event on the http stream, node pauses the stream and the end event is never triggered. request.resume() just tells it to let the stream continue anyway.

@phstc
Collaborator

Hi @edpaget, thanks for the explanation. :smile:

I updated my Node to v0.10.0 and got you PR, for me the testing is freezing on should be listening.

once an http server is listening with a callback
✓ should be listening

Is it working for you?

@edpaget

@phstc It hangs there for a while, but then continues on my machine. I'm a little lost on how things are working on Vows (I've only used Jasmine and Mocha), so I haven't figured out why it sits forever on that test.

@phstc phstc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. @edpaget
Commits on Mar 15, 2013
  1. @edpaget
This page is out of date. Refresh to see the latest.
View
4 README.md
@@ -25,6 +25,7 @@ Synopsis
//
file.serve(request, response);
});
+ request.resume();
}).listen(8080);
API
@@ -59,6 +60,7 @@ the HTTP request and response object:
request.addListener('end', function () {
fileServer.serve(request, response);
});
+ request.resume();
}).listen(8080);
### Serving specific files #
@@ -78,6 +80,7 @@ For example, you could serve an error page, when the initial request wasn't foun
}
});
});
+ request.resume();
}).listen(8080);
More on intercepting errors bellow.
@@ -101,6 +104,7 @@ has been served successfully, or if there was an error serving the file:
}
});
});
+ request.resume();
}).listen(8080);
Note that if you pass a callback, and there is an error serving the file, node-static
View
1  bin/cli.js
@@ -98,6 +98,7 @@ require('http').createServer(function (request, response) {
}
});
});
+ request.resume();
}).listen(+argv.port);
console.log('serving "' + dir + '" at http://127.0.0.1:' + argv.port);
View
2  test/integration/node-static-test.js
@@ -23,6 +23,7 @@ suite.addBatch({
else
request.end();
});
+ request.resume();
});
}).listen(TEST_PORT, this.callback)
},
@@ -61,6 +62,7 @@ suite.addBatch({
request.addListener('end', function () {
fileServer.serve(request, response);
});
+ request.resume();
}).listen(TEST_PORT, this.callback)
},
'should be listening' : function(){
Something went wrong with that request. Please try again.