-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic port switching #516
Changes from 5 commits
ed8ea2e
bd985de
5a3b73b
56cf7ab
cc24015
4e92c42
50296ed
0dc1ace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,23 +37,29 @@ const program = require('commander'); | |
|
||
program.option('--port <number>', 'Specify port number').parse(process.argv); | ||
|
||
const port = parseInt(program.port, 10) || 3000; | ||
|
||
tcpPortUsed | ||
.check(port, 'localhost') | ||
.then(function(inUse) { | ||
if (inUse) { | ||
console.error(chalk.red('Port ' + port + ' is in use')); | ||
process.exit(1); | ||
} else { | ||
console.log('Starting Docusaurus server on port ' + port + '...'); | ||
// start local server on specified port | ||
const server = require('./server/server.js'); | ||
server(port); | ||
} | ||
}) | ||
.catch(function(ex) { | ||
setTimeout(function() { | ||
throw ex; | ||
}, 0); | ||
}); | ||
var port = process.env.PORT || 3000; | ||
checkPort(); | ||
|
||
function checkPort() { | ||
tcpPortUsed | ||
.check(port, 'localhost') | ||
.then(function(inUse) { | ||
if (inUse) { | ||
console.error(chalk.red('Port ' + port + ' is in use')); | ||
// Try again but with port + 1 | ||
port += 1; | ||
checkPort(); | ||
// process.exit(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be entirely removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, do you mean that those 4 lines should all be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, just the line you commented out. There's no need to leave it in |
||
} else { | ||
console.log('Starting Docusaurus server on port ' + port + '...'); | ||
// start local server on specified port | ||
const server = require('./server/server.js'); | ||
server(port); | ||
} | ||
}) | ||
.catch(function(ex) { | ||
setTimeout(function() { | ||
throw ex; | ||
}, 0); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the behavior from listening to the --port argument on the command line to use the PORT environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revert this line.
EDIT: Just saw #588