Skip to content

Instantly share code, notes, and snippets.

@romaricpascal
Last active December 20, 2015 04:59
Show Gist options
  • Save romaricpascal/6075207 to your computer and use it in GitHub Desktop.
Save romaricpascal/6075207 to your computer and use it in GitHub Desktop.
Gruntfile configuring grunt-express and grunt-open to serve your projects file and open a browser, as a first step in my Grunt and livereload tutorial : http://rhumaric.com/2013/07/renewing-the-g…vereload-magic/
// Gruntfile with the configuration of grunt-express and grunt-open. No livereload yet!
module.exports = function(grunt) {
// Load Grunt tasks declared in the package.json file
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Configure Grunt
grunt.initConfig({
// grunt-express will serve the files from the folders listed in `bases`
// on specified `port` and `hostname`
express: {
all: {
options: {
port: 9000,
hostname: "0.0.0.0",
bases: [__dirname] // Replace with the directory you want the files served from
// Make sure you don't use `.` or `..` in the path as Express
// is likely to return 403 Forbidden responses if you do
// http://stackoverflow.com/questions/14594121/express-res-sendfile-throwing-forbidden-error
}
}
},
// grunt-open will open your browser at the project's URL
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= express.all.options.port%>'
}
}
});
// Creates the `server` task
grunt.registerTask('server', [
'express',
'open',
'express-keepalive'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment