PhusionPassenger.on('request', function(headers, socket) {
var req = createIncomingMessage(headers, socket);var res = new http.ServerResponse(req);res.assignSocket(socket);res.shouldKeepAlive = false;res.once('finish', function() {socket.destroySoon();});app(req, res);});
Replace the following line in your Node.js script:http.createServer(app).listen(...)with the following:PhusionPassenger.createServer(app);
var http = require('http');var PORT = process.env.PORT || 3456;var app = function(req, res){console.log(JSON.stringify(req.headers));var reqBody = '';req.setEncoding('utf8');req.on('data', function(chunk){reqBody += chunk;});req.on('end', function(){var resBody = 'Got '+reqBody.length+' bytes of request body:\n'+reqBody+'\n';console.log(resBody);res.writeHead(200, { 'Content-Length': resBody.length, 'Content-Type': 'text/plain' });res.write(resBody);res.end();});};http.createServer(app).listen(PORT, function(){console.log('Express server listening on port ' + PORT);});
curl -i -d 'foo=bar' http://localhost:3456/
var express = require('express');var app = express();
// DON'T do http.createServer(), not sure why you need socket.io?
// all the gist codePhusionPassenger.on('request', function(headers, socket){var req = createIncomingMessage(headers, socket);var res = createServerResponse(req);app(req,res);});
PhusionPassenger.on('request', function(headers, socket) {var req = createIncomingMessage(headers, socket);
var res = createServerResponse(req);app(req, res);if (req.method === 'GET' && req.read() === null) {req.emit('end');}});
http.createServer(app).listen(PORT, function(){console.log('Express server listening on port ' + PORT);});
var server = http.createServer(app);if (typeof PhusionPassenger === 'undefined') {server.listen(PORT, function(){
console.log('Express server listening on port ' + PORT);});}
else {PhusionPassenger.use(server).listen(); // prefer without the .listen()}
var http = require('http');
http.createServerWithoutPassenger = http.createServer;http.createServer = function(requestListener){return PhusionPassenger.use(http.createServerWithoutPassenger(requestListener));};require('./app');
http.createServer = function(requestListener){http.createServer = function(rl2){console.log("WARNING: Your app is using PhusionPassenger and calling http.createServer multiple times. To do this correctly, please see the documentation at https://groups.google.com/forum/#!topic/phusion-passenger/sZ4SjU8ypwc.");return http.createServerWithoutPassenger(rl2);};return PhusionPassenger.use(http.createServerWithoutPassenger(requestListener));};
After reading about server.js, I don't think using it is a good idea. 'Npm start' appears to be meant for starting servers/daemons. Since passenger initiates port binding, using server.js would not make sense.
The main property is used for require(), so I don't think Passenger should use it.
Heroku does not use web.js as a convention. It was mainly used as an example.
So that leaves app.js as the best candidate.
Sent from my Android phone.
--
--
You received this message because you are subscribed to a topic in the Google Groups "Phusion Passenger Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phusion-passenger/sZ4SjU8ypwc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phusion-passen...@googlegroups.com.