为什么我的nodemon服务器启动两次?

时间:2016-06-22 00:51:53

标签: gulp nodemon

我有下面的gulp文件,当我运行gulp websocket-server-start时,它可以正常工作。

但是,当我运行gulp tests时,websocket服务器启动了两次:

[19:33:25] Working directory changed to ~/PycharmProjects/test_stuff
[19:33:26] Using gulpfile ~/PycharmProjects/test_stuff/gulpfile.js
[19:33:26] Starting 'tests-compile'...
[19:33:26] Starting 'server-scripts'...
[19:33:26] Starting 'server-copy-static-assets'...
[19:33:27] Finished 'server-copy-static-assets' after 1.51 s
[19:33:28] Finished 'server-scripts' after 2.51 s
[19:33:28] Starting 'webserver-start'...
[19:33:28] Starting 'websocket-server-start'...
Websocket-server-start called
Starting websocket nodemon
[19:33:28] Finished 'websocket-server-start' after 15 ms
Starting websocket nodemon
[19:33:28] Finished 'tests-compile' after 2.56 s
Websocket Server is running on port 3000
Websocket Server is running on port 3000
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE 0.0.0.0:3000

什么可能导致服务器运行两次?

Gulpfile:

gulp.task("tests-compile", function () {
    var tsResult = gulp.src(paths.server.scripts.concat(paths.server.tests))
        .pipe(ts({
            "target": "ES5",
            "module": "amd",
            "sortOutput": true,
            "sourceMap": true,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "removeComments": false,
            "noImplicitAny": true
        })).js;
    return merge2(
        gulp.src([
            "node_modules/jquery/dist/jquery.js",
            "node_modules/jqueryui/jquery-ui.js",
            "node_modules/systemjs/dist/system.js",
            "node_modules/lodash/lodash.js",
            "node_modules/postal/lib/postal.js"
        ]),
        tsResult
    )
    .pipe(gulp.dest("DemoServer/tests/compiled_tests/"));
});


gulp.task('tests', ["tests-compile", "webserver-start", "websocket-server-start"], function (done) {
  return new Server({
    configFile: __dirname + '/DemoServer/tests/karma.conf.js',
    singleRun: true
  }, done).start();
});



gulp.task("server-scripts", function () {
    var tsResult = gulp.src(paths.server.scripts).pipe(ts({
        "target": "ES5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": true
    })).js;
    return tsResult
        .pipe(flatten())
        .pipe(gulp.dest("DemoServer/dist/"));
});

gulp.task("server-copy-static-assets", function() {
   return gulp.src(paths.server.static_assets)
       .pipe(gulp.dest("DemoServer/dist/static/"));
});


gulp.task("webserver-start", ['server-scripts', 'server-copy-static-assets'], function(callback) {
    nodemon({
        script: "DemoServer/dist/webserver.js",
        ext: 'js html',
        watch: [paths.server.scripts, paths.server.static_assets, paths.server.styles],
        env: {"NODE_ENV": "development"}
    });
});


gulp.task("websocket-server-start", ['server-scripts', 'server-copy-static-assets'], function(callback) {
    console.log("Websocket-server-start called");
    var websocket_server_started = false;
    nodemon({
        script: "DemoServer/dist/websocket_server.js",
        ext: 'js',
        watch: [paths.server.scripts, paths.server.static_assets],
        env: {"NODE_ENV": "development"}
    })
        .on('start', function () {
            console.log("Starting websocket nodemon");
            if(!websocket_server_started) {
                callback();
                websocket_server_started = true;
            }
        })
        .on('restart', function() { console.log("Restarting websocket nodemon");})
    ;
});

0 个答案:

没有答案