2

Something strange happens, when I try to connect to server. There are no errors in terminal, it says "Started connect web server on http://0.0.0.0:5555", then done without errors. But when I serf to http://localhost:5555/ - I get typical "page not found". In chrome console one warning and one error:

i18n-values: Missing value for "primaryParagraph"
http://localhost:5555/:1 GET http://localhost:5555/ net::ERR_CONNECTION_REFUSED

The more surprising is that when I define keepalive:true everything works fine. Really, I don't get why is it so.

My Gruntfile.js

'use strict';

module.exports = function( grunt ) {

// tasks
grunt.initConfig({
    // compile SASS
     sass: {
        dist: {
          files: [{
            expand: true,
            flatten: true,
            src: ['assets/source/sass/*.scss','app/shared/**/*.scss','app/components/**/*.scss'],
            dest: 'assets/source/css/',
            ext: '.css'
          }]
        }
    },

    // concat and minify CSS
    cssmin: {
        styles: {    
            files: {
                'public/css/style.min.css': ['assets/source/css/*.css','assets/source/libs/**/*.css','app/shared/**/*.css','app/components/**/*.css']
            }
        }
    },

    // autoprefix
    autoprefixer: {
        options: {
          browsers: ['> 1%', 'Android 2', 'last 2 versions', 'Firefox ESR', 'Opera 12.1', 'ie 7', 'ie 8', 'ie 9']
        },
        no_dest: {
          src: 'public/css/style.min.css'
        }
    },

    // compile Coffeescript
    coffee: {
      compile: {
        options: {
            separator: ';'
        },
        files: {
          'public/js/scripts.js': ['app/*.coffee','app/shared/**/*module*.coffee','app/shared/**/*.coffee','app/components/**/*module*.coffee','app/components/**/*.coffee']
        }
      }
    },

    // concat and minify JS
    concat: {
        options: {
            separator: ';'
        },
        scripts: {
            src: ['assets/source/libs/angular/angular.js', 'assets/source/js/*.js','assets/source/libs/*.js','assets/source/libs/**/*.js'],
            dest: 'public/js/vendor.js'
        }
    },

    uglify: {
        scripts: {
            files: {
                'public/js/scripts.min.js': 'public/js/scripts.js',
                'public/js/vendor.min.js': 'public/js/vendor.js'
            }
        }
    },

    // watch
    watch: {
        options: {
            livereload: true
        },
        scripts: {
            files: ['app/*module*.coffee','app/*routing*.coffee','app/*.coffee','app/shared/**/*module*.coffee','app/shared/**/*.coffee','app/components/**/*module*.coffee','app/components/**/*.coffee','assets/source/js/*.js','assets/source/libs/*.js','assets/source/libs/**/*.js'],
            tasks: [ 'coffee', 'concat', 'uglify' ]
        },
        css: {
            files: ['assets/source/sass/*.scss','app/shared/**/*.scss','app/components/**/*.scss','assets/source/css/*.css','assets/source/libs/**/*.css','app/shared/**/*.css','app/components/**/*.css'],
            tasks: [ 'sass', 'cssmin', 'autoprefixer' ]
        }
    },

    // minification
    imagemin: {
        dynamic: {
            files: [{
                expand: true,
                cwd: 'assets/img/',
                src: ['*.{png,jpg,gif}'],
                dest: 'public/img/'
            }]
        }
    },

    // bower
    bower: {
        install: {
          options: {
            targetDir: 'assets/source/libs/',
            layout: 'byComponent',
            cleanBowerDir: false
          }
        }
      },

    // server
      connect: {
        server: {
          options: {
            port: 5555
          }
        }
      }

});

grunt.loadNpmTasks( 'grunt-contrib-coffee');
grunt.loadNpmTasks( 'grunt-contrib-concat');
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-autoprefixer' );
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-contrib-connect');

// some default tasks

grunt.registerTask('default', [ 'coffee', 'concat', 'uglify' , 'sass', 'cssmin', 'autoprefixer']);
grunt.registerTask('publish', [ 'bower', 'coffee', 'concat', 'uglify' , 'sass', 'cssmin', 'autoprefixer']);
grunt.registerTask('serv', [ 'connect', 'watch']);
};
Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
onlydimon
  • 525
  • 4
  • 11

1 Answers1

1

Sorry to say, but that is just how Grunt connect works:

Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option, and can be enabled ad-hoc by running the task like grunt connect::keepalive.

This is an intentional feature. Grunt connect is only intended to be used while running build or test tasks, it is not intended to be a local server for playing around with a site.

If you need a small, local server for static files (html/css/js/image) then I would recommend the npm module "http-server". It's very easy to install and run:

~$ npm install -g http-server
~$ cd /path/to/your/project
~$ http-server

Good luck.

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
  • Thanks a lot for explanation and nmp server link. I settled the problem by running grunt along with watch task – onlydimon Dec 23 '14 at 15:21