forked from seajs/seajs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var print = require('util').print; | ||
var spawn = require('child_process').spawn; | ||
var static = require('node-static'); | ||
|
||
function createServer(dir, cmd) { | ||
dir = dir || '.'; | ||
|
||
// Server Start | ||
var file = new static.Server(fs.realpathSync(dir)); | ||
|
||
var server = http.createServer(function(request, response) { | ||
request.addListener('end', function() { | ||
file.serve(request, response); | ||
}).resume(); | ||
}); | ||
|
||
server.listen(9012, function() { | ||
if (cmd) { | ||
var args = cmd.split(' '); | ||
args = args.map(function(arg) { | ||
return arg.trim(); | ||
}); | ||
args = args.filter(function(arg) { | ||
return arg.length; | ||
}); | ||
var runner = spawn(args[0], args.slice(1)); | ||
runner.stdout.on('data', function(data) { | ||
print(data.valueOf()); | ||
}); | ||
runner.on('exit', function(code) { | ||
if (code === 127) { | ||
print(cmd + ' not available'); | ||
} | ||
server.close(); | ||
process.exit(code); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
var dir = process.argv[2] || '.'; | ||
var cmd = process.argv.slice(3); | ||
createServer(dir, cmd.join(' ')); |