javascriptnode.jsservergruntjsgrunt-connect

grunt connect exits instead of serving local files


I've got a following Gruntfile.js which includes only two tasks: the first one parses/generates files and the second one, grunt-contrib-connect, starts web server:

module.exports = function(grunt) {

  grunt.initConfig({
    aglio: {
      docs: {
        files: {
          'index.html': 'api.md',
        },
        options: {
          theme: "slate"
        }
      }
    },
    connect: {
      server: {
        options: {
          port: 9001,
          hostname: 'localhost',
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-aglio');

  grunt.registerTask('default', ['aglio', 'connect']);
};

The problem is that the server exits silently and I don't know why. In the console, it looks like this:

tducin@tducin-home:~/Workspace/duck-blueprint$ grunt
Running "aglio:docs" (aglio) task
>> Written to index.html

Running "connect:server" (connect) task
Started connect web server on http://localhost:9001

Done, without errors.

Can anybody point me on what is wrong with my connect task configuration?


Solution

  • Did you read the documentation of grunt-contrib-connect?

    According to the document.You need to set keepalive true if want keep alive the server after grunt tasks compleated.

    connect: {
      server: {
        options: {
          port: 9001,
          hostname: 'localhost',
          keepalive : true
        }
      }
    

    Keep the server alive indefinitely. Note that if this option is enabled, any tasks specified after this task will never run. By default, once grunt's tasks have completed, the web server stops. This option changes that behavior.

    https://github.com/gruntjs/grunt-contrib-connect/blob/master/README.md