grunt-express icon indicating copy to clipboard operation
grunt-express copied to clipboard

livereload option doesn't insert livereload script

Open azhang opened this issue 10 years ago • 2 comments

My grunt express settings:

express: {
  options: {
    port: 3000
  },
  livereload: {
    options: {
      livereload: true,
      bases: "build",
      server: path.resolve('server/grunt-index.js'),
      showStack: true,
      middleware: [
        function myMiddleware(req, res, next) {
          console.log("here");
        }
      ]
    }
  }
},

I'm using the example under "if you want to use both express and socket.io". I added a console.log to see which middleware is loaded.

exports.use = function() {
  console.log(arguments[0]);
  app.use.apply(app, arguments);
};

and I get the following before the server is started.

[Function: myMiddleware] <-- from grunt middleware option
[Function: staticMiddleware]
{ [Function: livereload] middlewarePriority: -1 }

myMiddleware is definitely loaded correctly - I see here in the console for every response. staticMiddlware is also definitely loaded - I can access the files in my build folder.

However, livereload isn't loaded correctly. I added some console.logs inside node_modules/grunt-express/node_modules/connect-livereload/index.js to see if it's ever called, and it isn't. In node_modules/grunt-express/lib/util.js, I've also added a console.log to rearrangeMiddleware:

exports.rearrangeMiddleware = function rearrangeMiddleware(server) {
  console.log("server.stack", server.stack);
  server.stack = (server.stack || []).sortBy(function(mw) {
    return mw.handle.middlewarePriority || 99;
  });
}

server.stack is undefined here, so I don't think middlewarePriority: -1 is working.

azhang avatar May 13 '14 15:05 azhang

By the way I'm using express4. I know app.stack existed in express3 but not sure if that's the case anymore. I'll update when I find out.

update: app.stack in express3 is now app._router.stack in express4.

azhang avatar May 13 '14 15:05 azhang

Pull request here: https://github.com/blai/grunt-express/pull/62

azhang avatar May 13 '14 18:05 azhang