Skip to content

Instantly share code, notes, and snippets.

@danheberden
Created November 15, 2012 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danheberden/4081477 to your computer and use it in GitHub Desktop.
Save danheberden/4081477 to your computer and use it in GitHub Desktop.
var http = require('http');
var static = require('node-static');
grunt.registerTask( 'server', "Create a preview server", function( port ) {
var done = this.async();
port = port || 8080;
var fileServer = new static.Server('./');
grunt.log.write( 'Creating server at http://localhost:' + port + '/ - go to http://localhost:' + port + '/quit to stop the server or CTRL-C this process' );
require('http').createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response, function( err, result ) {
console.log( request.url );
if ( request.url === "/quit" ) {
done();
}
if ( err ) {
console.dir( err );
}
});
});
}).listen( port );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment