Search code examples
gruntjsgrunt-contrib-connect

Using grunt-contrib-connect - open page URL with added context path


I have set up grunt connect like this:

connect: {
    options: {
        port: 9000,
        livereload: 35729,
        hostname: 'localhost'
    },
    livereload: {
        options: {
            open: true,
            base: [
                'app'
            ]
        }
    }
}

That works great - loads my index.html page as:

http://localhost:9000

However, to keep this consistent with how it will be loaded in production, I would like it to load it with additional context path added, like:

http://localhost:9000/myappcontext/secured

Can this be done simply with grunt-contrib-connect? Or do I need to add some other proxy/middleware?

Anyone got a simple example of this type of set-up?


Solution

  • Yes you can do this without much trouble, just configure the open option:

    connect: {
        options: {
            port: 9000,
            livereload: 35729,
            hostname: 'localhost'
        },
        livereload: {
            options: {
                open: {
                     target: 'http://localhost:9000/myappcontext/secured'
                },
                base: [
                    'app'
                ]
            }
        }
    }
    

    You can consult the README for more information about the available options.