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

Allow to run multiple styleguide servers on different ports. Fix #1019 #1021

Merged
Merged
Changes from all 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
15 changes: 9 additions & 6 deletions lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,21 +505,24 @@ module.exports.server = function(options) {
};

function startServer(options) {
// Ignore start server if we already have instance running
// Ignore start server if we already have instance running on the same port
if (!serverInstance) {
serverInstance = {};
}
if (!serverInstance[options.port]) {
var port = options.port;
serverInstance = sgServer(options);
serverInstance.app.set('port', port);
serverInstance.server.listen(serverInstance.app.get('port'), function() {
console.log('Express server listening on port ' + serverInstance.server.address().port);
serverInstance[port] = sgServer(options);
serverInstance[port].app.set('port', port);
serverInstance[port].server.listen(serverInstance[port].app.get('port'), function() {
console.log('Express server listening on port ' + serverInstance[port].server.address().port);
}).on('error', function(error) {
if (error.code === 'EADDRINUSE') {
console.error('Port:' + port + ' is already in use.');
console.error('Please provide port using --port <port>');
}
});
}
return serverInstance;
return serverInstance[options.port];
}

module.exports.addSection = addSection;