iriscouch / fastcgi Goto Github PK
View Code? Open in Web Editor NEWSimple, robust node.js web server that runs FastCGI applications
License: Apache License 2.0
Simple, robust node.js web server that runs FastCGI applications
License: Apache License 2.0
Adding TCP sockets support would allow to use more FastCGI modules.
I would like to suggest adding a requestHandler object to export which would allow you to mount the application on any compatible request handler. My implementation used a sort of promise object and basically copied the httpd method. It seems like it shouldn't have to be a promise object, but this is how it ended up. It could also be sent in the callback and then you would just call it in your code.
function getHandler(port, host, socket_path, callback){
var promise = { requestHandler: function(req, res){ throw new Exception("Promised object not ready yet. Check the ready property"); }, ready: false };
connect_fcgi(socket_path, 0, function(er, socket) {
if(er)
return callback(er)
fcgi_get_values(socket, function(er, values) {
if(er)
return callback(er)
values.FCGI_MPXS_CONNS = values.FCGI_MPXS_CONNS || 0
LOG.info('FCGI values: %j', values)
promise.requestHandler = fcgi_handler(port, host, values, socket, socket_path);
promise.ready = true;
return callback(null)
})
})
}
When using this in combination with graphite, the following error is received sporadically when trying to load the graphite web interface.
Get FastCGI values
Listening for FastCGI values
FCGI values: {"FCGI_MAX_CONNS":1024,"FCGI_MAX_REQS":1024,"FCGI_MPXS_CONNS":0}
Listening on 0.0.0.0:24093
GET / 200
GET /browser/header/ 200
GET /composer/? 200
STDERR: No handlers could be found for logger "rendering"
STDERR:
GET /render 200
GET /render/?width=586&height=308&_salt=1372100547.596 200
GET /favicon.ico 200
GET / 200
GET /browser/header/ 200
events.js:72
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:125:12)
at Socket.Writable.write (_stream_writable.js:170:5)
at Socket.write (net.js:596:40)
at process_request (/home/ubuntu/hosting/manager/node_modules/fastcgi/fastcgi.js:207:12)
at Server.on_request (/home/ubuntu/hosting/manager/node_modules/fastcgi/fastcgi.js:145:5)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2012:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:119:23)
at Socket.socket.ondata (http.js:1902:22)
at TCP.onread (net.js:510:27)
@jhs Through my investigation I believe it comes into play due to there not being an error handler here and the fact that streams2 must have changed the actual stream. Still digging in, just wanted to get this documented.
Hi,
I tried to use nodejs with fastcgi but failed to execute it. Any comments? Thanks
root@ubuntu12:/tmp# ./node_modules/fastcgi/cli.js --port=1234 --socket=/tmp/php-fpm.socket
Sending http requests to /tmp/php-fpm.socket
Get FastCGI values
Listening for FastCGI values
events.js:68
throw arguments[1]; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:769:11)
at Object.afterWrite (net.js:593:19)
root@ubuntu12:/tmp# node -v
v0.8.11
root@ubuntu12:/tmp# npm ls
/tmp
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└── [email protected]
When I run the server with Example 1 (TinyFastCGI) from the FastCGI documentation (changing the incorrect "SERVER_HOSTNAME" to "SERVER_NAME" in the code), I get the following crash:
$ node node_modules/fastcgi/cli.js --port=8888 --socket=/tmp/tinyfcgi
Sending http requests to /tmp/tinyfcgi
Get FastCGI values
Listening for FastCGI values
FCGI values: {"FCGI_MAX_CONNS":1,"FCGI_MAX_REQS":1,"FCGI_MPXS_CONNS":0}
Listening on 0.0.0.0:8888
Ignoring management record: {"header":{"version":1,"type":10,"recordId":0,"contentLength":0,"paddingLength":0},"body":{},"bodies":[]}
http.js:1140
var statusLine = 'HTTP/1.1 ' + statusCode.toString() + ' ' +
^
TypeError: Cannot call method 'toString' of undefined
at ServerResponse.writeHead (http.js:1140:45)
at send_stdout (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:411:19)
at Parser.on_record [as onRecord] (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:359:14)
at Parser._parser.execute (/home/roy/Projects/node_modules/fastcgi/node_modules/fastcgi-parser/lib/fastcgi.js:242:57)
at FastCGIStream.on_data (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:320:12)
at FastCGIStream.EventEmitter.emit (events.js:95:17)
at FastCGIStream.emit_records (/home/roy/Projects/node_modules/fastcgi/stream.js:181:10)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:111:17)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:151:8)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:151:8)
This happens because the example does not include a Status: 200
header. According to the CGI specification, section 9.2 states:
If the script does not return a Status header, then "200 OK" should be assumed.
The easy workaround is to have the fcgi program return a Status
header but it would be best if the fastcgi module (1) properly defaulted the status and (2) did not crash no matter what came over the socket.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.