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 reload works first time, but not subsequent times #37

Open
tauren opened this issue Oct 29, 2013 · 8 comments
Open

Server reload works first time, but not subsequent times #37

tauren opened this issue Oct 29, 2013 · 8 comments

Comments

@tauren
Copy link

tauren commented Oct 29, 2013

I have the following Gruntfile config:

  grunt.initConfig({
    express: {
      dev: {
        options: {
          port: 9000,
          hostname: '*',
          server: 'server',
          bases: ['.tmp','app'],
          livereload: true,
          serverreload: true,
          showStack: true
        }
      }
    },
    open: {
      dev: {
        url: 'http://localhost:<%= express.dev.options.port %>'
      }
    },
    watch: {
      javascript: {
        files: ['app/js/**/*.js', 'app/experiences/**/*.js'],
        tasks: ['jshint','lodashAutobuild:app','intern:phantom']
      },
      // server: {
      //   files: ['server/**/*.js'],
      //   tasks: ['express:dev']
      // },
      livereload: {
        options: {
          livereload: true
        },
        files: [
          'app/*.html',
          '{.tmp,app}/styles/*.css',
          '{.tmp,app}/js/**/*.js',
          'app/images/*.{png,jpg,jpeg}'
        ],
        tasks: ['devcode:dev']
      }
    }
    // SNIP -- other task configs

  });

  grunt.registerTask('foo', [
    'express:dev',
    'open:dev',
    'watch'
  ]);

Running grunt foo, and then hitting an endpoint, produces the following output:

: grunt foo
Running "express:dev" (express) task

Running "open:dev" (open) task

Running "watch" task
Waiting...OK

Running "express-server:dev:/var/folders/w2/gtt9j4h973db3_2wj1mklsn5h9zb96/T/express113928-43764-sg1fyu/dev.server" (express-server) task
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Web server started on port:9000, no hostname specified [pid: 43767]

Running "express-keepalive" task
post data123  { firstName: '',
  lastName: '',
  transactionId: '37f702d4-2a4a-4854-8ea1-920cc1818c761383005793096' }

Next I change the server code to output post dataXYZ and save the file, wait a few seconds, then hit the endpoint again. The following is output:

Scheduled tasks have been interrupted...OK
>> File "../../../../var/folders/w2/gtt9j4h973db3_2wj1mklsn5h9zb96/T/express113928-43764-sg1fyu/dev.server" changed.

Completed in 0.008s at Mon Oct 28 2013 17:16:47 GMT-0700 (PDT) - Waiting...
Running "express-server:dev:/var/folders/w2/gtt9j4h973db3_2wj1mklsn5h9zb96/T/express113928-43764-sg1fyu/dev.server" (express-server) task
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Web server started on port:9000, no hostname specified [pid: 43784]

Running "express-keepalive" task
post dataXYZ  { firstName: '',
  lastName: '',
  transactionId: 'b6c75bf7-14fb-46e4-84de-4a9af7cceac81383005822042' }
OK

That works perfectly! So I edit the server/index.js file again, changing it to say post data, save, wait a few seconds, then hit the endpoint again. Now I get this:

>> File "../../../../var/folders/w2/gtt9j4h973db3_2wj1mklsn5h9zb96/T/express113928-43764-sg1fyu/dev.server" changed.

Running "express-server:dev:/var/folders/w2/gtt9j4h973db3_2wj1mklsn5h9zb96/T/express113928-43764-sg1fyu/dev.server" (express-server) task
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Port 9000 in use
Web server started on port:9001, no hostname specified [pid: 43795]

Running "express-keepalive" task
post dataXYZ  { firstName: '',
  lastName: '',
  transactionId: '11d4e880-490d-42cd-8ad0-0493975a669b1383005847423' }

As you can see, it complains that port 9000 is in use, so it starts up a new server on port 9001. However, hitting the endpoint on either 9000 or 9001 both output post dataXYZ instead of post data.

Also, note there are a lot of deprecation messages regarding connect 3.0.

@tauren
Copy link
Author

tauren commented Oct 30, 2013

Furthermore, it appears that livereload doesn't work when serverreload: true. By removing the serverreload config option, then livereload starts working again.

@tauren
Copy link
Author

tauren commented Oct 30, 2013

Perhaps this is related to #36. Note that I'm having troubles on OSX. My server is a single JS file in server/index.js.

@mccool
Copy link

mccool commented Mar 22, 2014

I'm having the same issue where the server reload does not stop the server running so it puts it on the next open port. The connect 3.0 messages are coming from express. The express 4.x doc states "As of 4.x, Express no longer depends on Connect. All of Express' previously included middleware are now in separate repos. Please view the list of middleware. The only included middleware is now express.static()."

I may just run my express app in node and grunt live reload until this issue is resolved. This is very promising though.

@ghost
Copy link

ghost commented Mar 29, 2014

I'm having the same problem here. First reload works then next port is assigned. Reload works then next ports is assigned...

@srigi
Copy link

srigi commented Apr 23, 2014

Same here. This needs to be fixed, otherwise developments is just pain.

@danielcrisp
Copy link

It seems the problem is with grunt-contrib-watch as detailed here: #22

I upgraded to the latest version of grunt-contrib-watch, currently v0.6.1 and everything is working perfectly now :-)

@olegberman
Copy link

Try using the task called 'express-restart'

@henryng24
Copy link

@danielcrisp @olegberman

The behavior I'm getting is such that live-reloading doesn't work on the front-end UNLESS you reload the server first. livereload and serverreload is set to true.

SCENARIO 1:

  1. Make changes to the server (server reloads and reflects changes)
  2. Make changes to the front-end (JS/HTML/CSS) (front-end reloads and reflects changes on all subsequent front-end changes)
  3. Make changes to the server again (server reloads and reflects changes, server starts on another port; #### is in use, started server on port ####+1)
  4. Make changes to the front-end (nothing happens)

SCENARIO 2

  1. Make changes to the front-end (JS/HTML/CSS) (nothing happens)
  2. Make changes to the server (nothing happens)

Do your suggestions resolve these issues?

Thanks!

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

6 participants