[Pkg-javascript-commits] [node-static] 105/151: Removed 'end' event listener.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:18:01 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository node-static.
commit eeab04a946a2e8c28af97d130634eb1803e6a1a5
Author: Arjan Singh <arjan.singh at gmail.com>
Date: Sun Mar 24 23:29:17 2013 -0700
Removed 'end' event listener.
The example did not work out of the box. I traced the problem to the 'end' event listener attached to request.
I guess older versions of node.js required this but as of 0.10.0 (probably earlier), the `createServer` callback isn't called until `request` has already completed.
Therefore, there is no need for the 'end' event listener anymore.
Also, I removed some unnecessary parentheses.
---
examples/file-server.js | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/examples/file-server.js b/examples/file-server.js
index f133b80..4f0796e 100644
--- a/examples/file-server.js
+++ b/examples/file-server.js
@@ -3,22 +3,17 @@ var static = require('../lib/node-static');
//
// Create a node-static server to serve the current directory
//
-var file = new(static.Server)('.', { cache: 7200, headers: {'X-Hello':'World!'} });
+var file = new static.Server('.', { cache: 7200, headers: {'X-Hello':'World!'} });
require('http').createServer(function (request, response) {
- request.addListener('end', function () {
- //
- // Serve files!
- //
- file.serve(request, response, function (err, res) {
- if (err) { // An error as occured
- console.error("> Error serving " + request.url + " - " + err.message);
- response.writeHead(err.status, err.headers);
- response.end();
- } else { // The file was served successfully
- console.log("> " + request.url + " - " + res.message);
- }
- });
+ file.serve(request, response, function (err, res) {
+ if (err) { // An error as occured
+ console.error("> Error serving " + request.url + " - " + err.message);
+ response.writeHead(err.status, err.headers);
+ response.end();
+ } else { // The file was served successfully
+ console.log("> " + request.url + " - " + res.message);
+ }
});
}).listen(8080);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git
More information about the Pkg-javascript-commits
mailing list