Last active
August 29, 2015 14:00
-
-
Save ifukazoo/11411160 to your computer and use it in GitHub Desktop.
静的webサーバ
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 filePath = process.argv[2]; | |
var connect = require('connect'), | |
http = require('http'), | |
child_process = require('child_process'), | |
port = '', | |
directory = '.'; | |
if (process.argv.length !== 3) { | |
console.log("usage:" + process[1] + " <port>"); | |
process.exit(1); | |
} | |
port = process.argv[2]; | |
child_process.exec('ifconfig |grep -1 "^eth0" |grep inet', function(err, stdout, stderr) { | |
if (err) throw err; | |
var address = stdout.match(/(\d{1,3}\.){3}\d{1,3}/)[0]; | |
console.log('ip = ' + address); | |
console.log('port = ' + port); | |
connect() | |
.use(connect.logger('short')) | |
.use(connect.static(directory)) | |
.listen(port); | |
console.log('server listening ...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment