3

Trying to get grunt-connect setup. What I want is to start a server (either localhost or an IP), the browser to open at that url and ideally this to livereload when a CSS, HTML or JS file is changed. But we can come to that later.

This is what I have in the gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        includesPath: "includes",
        connect: {
            test: {
                port: 9001,
                hostname: '0.0.0.0',
                base: '',
                open: true
            }
        }
    });

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

    grunt.registerTask('default', ['connect:test']);
    grunt.registerTask('server', ['connect:test']);
};

this is the dependency in the package.json

"grunt-contrib-connect": "~0.8.0"

When I run either grunt or grunt server the Terminal window says

Started connect web server on http: //0.0.0.0:8000

It doesn't open a browser. If I go to that address in the browser, there is no page there.

What do you reckon?

Leads
  • 839
  • 2
  • 10
  • 27

2 Answers2

3

So it seems I was missing the options object! What a stupid, Friday afternoon mistake that was. Frustrating that it didn't error though, I assume it has default settings it uses, which would explain why it used it's on port? This code did the trick, thanks for your help Dave McNally

connect: {
            server: {
                options: {
                    keepalive: true,
                    port: 4000,
                    base: '.',
                    open: true
                }
            }
        }
Leads
  • 839
  • 2
  • 10
  • 27
0

You’ll want a value in the base parameter, the default '.' will do if source is in same root directory and as mentioned, you don't need to specify hostname when using the default. Also, check ports, as you're specifying one in the task but then opening another in the given address?

  • though I specify the port the message in the terminal says it's at :8000. So this doesn't work either: http://0.0.0.0:9001/ – Leads Aug 01 '14 at 14:49
  • Not sure if there could be conflicts on specified port. Have you tried specifying 8000 in your task? – Dave McNally Aug 01 '14 at 14:51
  • No difference I'm afraid. What the heck is going on :) – Leads Aug 01 '14 at 14:53
  • You would run into issues if the port is already in use but as 8000 is also giving same result, issue must be elsewhere. I would double check paths to ensure there’s a page in the location connect is looking at? Using '.' will point to the same location as the Gruntfile is situated. Do you have an index.html there from build? – Dave McNally Aug 01 '14 at 14:56
  • I do. Tell you what, I have leave now but over the weekend I'll create a zip with the core basics of what I have, and see if it works for anyone else :) could be a machine issue. – Leads Aug 01 '14 at 15:02
  • here we go: https://www.dropbox.com/s/tylq8pg9dgpk61x/connecttest.zip Hopefully that downloads ok. A very basic grunt file, trying to set up a few servers in a few different ways. None of which seem to work for me. If someone would be lovely enough to try it and let me know... – Leads Aug 01 '14 at 16:52