Skip to content

Commit

Permalink
Merge pull request sintaxi#504 from alexgleason/refactor-cli-script
Browse files Browse the repository at this point in the history
Refactored CLI script to allow port 0
  • Loading branch information
sintaxi committed Jan 7, 2016
2 parents 7fa6f99 + a9ec086 commit 0b8e8c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 11 additions & 14 deletions bin/harp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,12 @@ program
.description("Start a Harp server in current directory")
.action(function(path, program){
var projectPath = nodePath.resolve(process.cwd(), path || "")
var ip = program.ip || '0.0.0.0'
var port = program.port || 9000
harp.server(projectPath, { ip: ip, port: port }, function(){
var address = ''
if(ip == '0.0.0.0' || ip == '127.0.0.1') {
address = 'localhost'
} else {
address = ip
}
var hostUrl = "http://" + address + ":" + port + "/"
if(typeof program.ip == 'undefined') program.ip = '0.0.0.0'
if(typeof program.port == 'undefined') program.port = 9000
harp.server(projectPath, { ip: program.ip, port: program.port }, function(){
var host = this.address()
if(host.address == '0.0.0.0' || host.address == '127.0.0.1') host.address = 'localhost'
var hostUrl = "http://" + host.address + ":" + host.port + "/"
output("Your server is listening at " + hostUrl)
})
})
Expand All @@ -103,12 +99,13 @@ program
.description("Start a Harp server to host a directory of Harp projects")
.action(function(path, program){
var projectPath = nodePath.resolve(process.cwd(), path || "")
var port = program.port || 9000
harp.multihost(projectPath, { port: port }, function(){
if(port == "80"){
if(typeof program.port == 'undefined') program.port = 9000
harp.multihost(projectPath, { port: program.port }, function(){
var host = this.address()
if(host.port == "80"){
var loc = "http://harp.nu"
}else{
var loc = "http://harp.nu:" + port
var loc = "http://harp.nu:" + host.port
}
output("Your server is hosting multiple projects at " + loc)
})
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ exports.multihost = function(dirPath, options, callback){
app.use(middleware.process)
app.use(middleware.fallback)
app.listen(options.port || 9000, callback)

return app
}

/**
Expand Down

0 comments on commit 0b8e8c3

Please sign in to comment.