OK.
When I make the change in http.js this is what I get when I hit nginx.
Config is nginx is listening on 80 and reverse proxying to a node.js
server on port 8000.
So when I hit nginx:
[eugene@eugenes-macbook /usr/local/lib/node/libraries]$ curl -i
http://localhost
HTTP/1.1 200 OK
Server: nginx/0.7.64
Date: Sat, 05 Dec 2009 03:41:42 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Hello World = 8000
---
Here are the headers received by the node.js server:
[eugene@eugenes-macbook ~/Documents/work/nodedev/example] master$ ./
example.js -p 8000
Server running at
http://127.0.0.1:8000/
user-agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4
OpenSSL/0.9.8k zlib/1.2.3
host: localhost:8000
accept: */*
host:
127.0.0.1:8000
connection: close
user-agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4
OpenSSL/0.9.8k zlib/1.2.3
accept: */*
----
no problems there. When I now go straight to the node.js server
listening on port 8000, however:
[eugene@eugenes-macbook /usr/local/lib/node/libraries]$ curl -i
http://localhost:8000
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: keep-alive
--- (it just hangs - actually it waits for a few minutes and then
returns) ---
The headers received by the node.js server:
[eugene@eugenes-macbook ~/Documents/work/nodedev/example] master$ ./
example.js -p 8000
Server running at
http://127.0.0.1:8000/
user-agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4
OpenSSL/0.9.8k zlib/1.2.3
host: localhost:8000
accept: */*
--- (just hanging - but the http version is 1.0 - i've verified this)
---
Here is my example node.js server:
#!/usr/bin/env node
var sys = require('sys'),
http = require('http'),
optparse = require('optparse');;
var SWITCHES = [
['-p', '--port-number [PORT_NUMBER]', "Portnumber to listen to"],
['-H', '--help', "Shows this help section"],
];
// Internal variable to store options.
var options = {
port: 8000
};
// Create a new OptionParser with defined switches
var parser = new optparse.OptionParser(SWITCHES);
parser.banner = 'Usage: example.js [options]';
// Handle the --print switch
parser.on('port-number', function(value) {
options.port = parseInt(value);
});
// Handle the --help switch
parser.on('help', function() {
sys.puts(parser.toString());
});
// Parse command line arguments
parser.parse(process.ARGV);
http.createServer(function (req, res) {
for (var i in req.headers) {
sys.puts(i + ": " + req.headers[i]);
}
res.sendHeader(200, {'Content-Type': 'text/plain'});
res.sendBody('Hello');
res.flush();
setTimeout(function () {
res.sendBody(' World = ' + options.port);
res.finish();
}, 2000);
}).listen(options.port);
sys.puts('Server running at
http://127.0.0.1:' + options.port + '/');
Any ideas?