mdlawson / piping

Keep your code piping hot! Live code reloading without additional binaries
MIT License
219 stars 13 forks source link

Weird issue when running with latest express #13

Open andrewmunro opened 8 years ago

andrewmunro commented 8 years ago

I have my piping code setup as such:

#!/usr/bin/env node
if (process.env.NODE_ENV !== 'production') {
    if (!require('piping')({
            hook: true,
            ignore: /(\/\.|~$|\.json$)/i
        })) {
        return;
    }
}

var express = require('express');
var http = require('http');

var app = express();
app.server = http.createServer(app);

app.server.listen(process.env.PORT || 8080);

console.log('Started on port' + app.server.address().port);

For some odd reason, when running this simple app with piping, app.server.address() returns null. If I run this code without piping, it returns the port as expected.

Using "express": "^4.13.4" and "piping": "^0.3.0",

Any ideas?

mntnoe commented 8 years ago

Hmm, it seems to be an issue with creating http servers on workers in general. The server still runs, though:

var cluster = require("cluster");

if (cluster.isMaster) {
  cluster.fork();
}
else {
  var http = require('http');
  var server = http.createServer(function(req, res) { res.end('ok'); });
  server.listen(process.env.PORT || 8080);
  console.log('Server address: ' + server.address());
}

I have been unable to find an explaination of this behavior, though.

d-oliveros commented 7 years ago

I'm having the same issue. I had to replace piping with nodemon for tests to work (using mocha). This issue was not apparent until I tried testing an express server with supertest, as supertest makes heavy use of app.server.address().