BrowserSync使用Express / Gulp持续进行GET

时间:2015-04-03 20:12:42

标签: node.js express gulp browser-sync

我正在运行Express服务器并使用browserSync来监视更改。当我运行npm start时,它会启动一个运行的gulp任务:

// Server task
gulp.task('server', function(cb) {

  // We use this `called` variable to make sure
  // the callback is only executed once
  var called = false;

  return nodemon({
    script: 'server.js',
    watch: ['server.js', 'app/**/*.js', 'config/**/*.js']
  })
  .on('start', function onStart() {
    if (!called) {
      cb();
    }
    called = true;
  })
  .on('restart', function onRestart() {

    // Also reload the browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, 500);
  });
});

// BrowserSync
gulp.task('browser-sync', ['server'], function() {
    browserSync.init({

      // All of the following files will be watched
      files: ['public/**/*.*'],

      // Tells BrowserSync on where the express app is running
      proxy: 'http://localhost:3000',
      port: 4000,
      open: false,
      notify: false,
      logPrefix: project.name,
      logConnections: false,
      logLevel: 'silent'
    });
  });

但是,在终端窗口中,它会继续显示以下内容:

GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521010-28291 200 10.482 ms - -
GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521032-28292 200 10.573 ms - -
GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521053-28293 200 8.754 ms - -
GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521082-28294 200 7.013 ms - -
GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521110-28295 200 8.339 ms - -
GET /browser-sync/socket.io/?EIO=3&transport=polling&t=1428091521134-28296 200 12.367 ms 

造成这种情况的原因是什么?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。退出powershellrestarting firefox解决了问题。

希望这有帮助!