Created
November 15, 2012 21:36
-
-
Save danheberden/4081477 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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