Created
November 4, 2012 11:58
-
-
Save zerojuan/4011591 to your computer and use it in GitHub Desktop.
http-server
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
#!/usr/bin/env node | |
var colors = require('colors'), | |
httpServer = require('../lib/http-server'), | |
argv = require('optimist').argv; | |
if (argv.h || argv.help) { | |
console.log([ | |
"usage: http-server [path] [options]", | |
"", | |
"options:", | |
" -p Port to use [8080]", | |
" -a Address to use [0.0.0.0]", | |
" -i Display autoIndex [true]", | |
" -s --silent Suppress log messages from output", | |
" -h --help Print this list and exit.", | |
].join('\n')); | |
process.exit(); | |
} | |
var port = argv.p || 8080, | |
host = argv.a || '0.0.0.0', | |
log = (argv.s || argv.silent) ? (function () {}) : console.log; | |
var options = { | |
root: argv._[0], | |
autoIndex: argv.i, | |
cache: argv.c | |
}; | |
function onListening() { | |
log('Starting up http-server, serving '.yellow | |
+ server.root.cyan | |
+ ' on port: '.yellow | |
+ port.toString().cyan); | |
log('Hit CTRL-C to stop the server'); | |
} | |
var server = httpServer.createServer(options); | |
server.listen(port, host, onListening); | |
if (process.platform !== 'win32') { | |
// | |
// Signal handlers don't work on Windows. | |
// | |
process.on('SIGINT', function () { | |
log('http-server stopped.'.red); | |
process.exit(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment