blai / grunt-express

Start an Express.js web server using grunt.js
MIT License
254 stars 41 forks source link

Placeholders not working with Express 4 #64

Open dhaub opened 10 years ago

dhaub commented 10 years ago

The statics and middleware are all placed at the end of the express pipeline in version 4. This appears to be because the pipeline has been moved from the application variable "stack" to be part of the application's "_router" object.

References to server.stack in the util.js file need to be changed to server._router.task when working with express 4.

aktary commented 10 years ago

How are you able to see what the express pipeline is? I'm having a very frustrating time with getting grunt-express to set the bases properly and I'd love to see what the pipeline is at runtime.

dhaub commented 10 years ago

I've also run into some problems with the pipeline being reordered. I believe I have it fixed, but I've been unable to get the automated tests to work, so I've been trying to manually test. If you'd like to help test, check out my fork of the project it has the latest fix in it. https://github.com/dhaub/grunt-express ( https://github.com/dhaub/grunt-express.git)

On Thu, Jul 3, 2014 at 3:34 PM, aktary notifications@github.com wrote:

How are you able to see what the express pipeline is? I'm having a very frustrating time with getting grunt-express to set the bases properly and I'd love to see what the pipeline is at runtime.

— Reply to this email directly or view it on GitHub https://github.com/blai/grunt-express/issues/64#issuecomment-47974675.

aktary commented 10 years ago

Did you guys see that the build is failing? There's something wonky with the dependencies...

aktary commented 10 years ago

I've upgraded to 1.4.0 and it's working... except that it killed my passportjs implementation when I had the staticsPlaceholder above the passport.initialize. Not sure why, but it did. Once I moved it below, everything is fine again.

mhuggins commented 10 years ago

I'm trying to use grunt-express (1.4.1), and I think I'm hitting the same problem. I'm getting an error message...

Warning: Cannot call method 'findIndex' of undefined Use --force to continue.

...from inside this grunt-express function:

function findPlaceholder(server, placeholderName) {
  var stackHolder = server._router || server;
  return stackHolder.stack.findIndex(function (mw) {
    return mw.handle.name === placeholderName;
  });
}

It looks like this grunt task is trying to call stack on my express server, which is undefined. Any advice?

mhuggins commented 10 years ago

Downgrading from 1.4.1 to 1.4.0 seems to fix the problem. Oddly enough, npm has version 1.4.1 as the latest even though master still shows 1.4.0 in package.json.

dhaub commented 10 years ago

Any chance of getting a small project that demonstrates the error so that we can fix it?

On Tue, Aug 19, 2014 at 6:45 PM, Matt Huggins notifications@github.com wrote:

Downgrading from 1.4.1 to 1.4.0 seems to fix the problem. Oddly enough, npm has version 1.4.1 as the latest even though master still shows 1.4.0 in package.json.

— Reply to this email directly or view it on GitHub https://github.com/blai/grunt-express/issues/64#issuecomment-52711065.

nate250 commented 9 years ago

The provided example with socket.io should do this.

Alternatively, here is my code that is running into the same problem:

var express = require('express');
var app = express();
var http = require('http');
var WebSocketServer = require('ws').Server;
var server = http.createServer(app);

var wss = new WebSocketServer({server: server, path: '/my/path'});
wss.on('connection', function(ws) {
    console.log('WebSocket emulator UP');
});

exports = module.exports = server;
exports.use = function() {
    app.use.apply(app,arguments);
};
mhuggins commented 9 years ago

Ugh, I just ran into this again. Took some searching to remember this is the npm package that's causing it.

GuillaumeLeclerc commented 9 years ago

Hello, Do you have any news on this ?