Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server not stopping before restart when editing Gruntfile.js #22

Closed
pensierinmusica opened this issue Oct 13, 2013 · 6 comments
Closed
Assignees

Comments

@pensierinmusica
Copy link

Hi,

I have Grunt "watch" looking at some files and restarting Express if they get changed.

It all works seamlessly. For some weird reason though if the file edited is Gruntfile.js, grunt-express-server doesn't stop Express before relaunching when the express:dev task is triggered by grunt-watch and obviously it generates an EADDRINUSE error.

This is my grunt-watch configuration:

    watch: {
      options: {
        livereload: true
      },
      stylus: {
        files: ['<%= yeoman.app %>/styles/sections/*.styl'],
        tasks: ['stylus'],
        options: {livereload: false}
      },
      autoprefixer: {
        files: ['<%= yeoman.app %>/styles/*.css'],
        tasks: ['autoprefixer']
      },
      express: {
        files: [
          'app.js',
          'config/*.js',
          'controllers/*.js',
          'models/*.js',
          'Gruntfile.js'
        ],
        tasks: ['express:dev'],
        options: {spawn: false} // Without this option specified express won't be reloaded
      }

And this is my grunt-express-server configuration:

    express: {
      options: {
        port: process.env.PORT || 3000
      },
      dev: {
        options: {
          script: 'app.js'
        }
      },
      prod: {
        options: {
          script: 'app.js',
          node_env: 'production'
        }
      }
    }

The weird thing is that the problem ony happens with Gruntfile.js. If I modify, let's say, app.js or one of the controllers, the task correctly stops Express before reloading it.

Any thoughts?? Thanks!

@ericclemmons
Copy link
Owner

I'm not really sure yet, but I have to ask, why restart the server if the Gruntfile changes?

@pensierinmusica
Copy link
Author

I guess you're right... I could just live-reload the browser :)

@jalcine
Copy link

jalcine commented Nov 15, 2013

I'm having this issue when I'm editing my package.json and wanting to reload the server to include new packages like middleware and the likes.

@ericclemmons
Copy link
Owner

Wow, that's really odd! I was able to reproduce it, & trying to figure out why Gruntfile.js changes would cause this!

@ericclemmons
Copy link
Owner

Apparently Gruntfile.js is auto-watched, which doesn't properly emit the proper signals to kill the server. As a result, the next iteration of watch seems to run the task in a new namespace, meaning the server never shuts down.

Trying an alternative now...

@ericclemmons
Copy link
Owner

Aha! Stupid Grunt being clever. I'm having to introduce process._servers to keep the server in memory for stopping, since Grunt explicitly clears the require cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants