Skip to content
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

Merged
merged 8 commits into from
Apr 10, 2018
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions lib/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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.

Copy link
Contributor

@yangshun yangshun Apr 20, 2018

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

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be entirely removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, do you mean that those 4 lines should all be removed?

Copy link
Contributor

@yangshun yangshun Apr 10, 2018

Choose a reason for hiding this comment

The 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);
});
}