Skip to content

Commit

Permalink
Merge pull request #198 from kadirahq/listen-on-all
Browse files Browse the repository at this point in the history
Listen on all hosts by default
  • Loading branch information
Muhammed Thanish committed May 16, 2016
2 parents 52e5b4a + 91c8d6b commit 464a463
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 12 additions & 4 deletions dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

var logger = console;

_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-s, --static-dir [dir-name]', 'Directory where to load static files from').option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').parse(process.argv);
_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-h, --host [string]', 'Host to run Storybook').option('-s, --static-dir [dir-name]', 'Directory where to load static files from').option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').parse(process.argv);

if (!_commander2.default.port) {
logger.error('Error: port to run Storybook is required!\n');
_commander2.default.help();
process.exit(-1);
}

// Used with `app.listen` below
var listenAddr = [_commander2.default.port];

if (_commander2.default.host) {
listenAddr.push(_commander2.default.host);
}

var app = (0, _express2.default)();

if (_commander2.default.staticDir) {
Expand Down Expand Up @@ -98,10 +105,11 @@ app.get('/iframe.html', function (req, res) {
res.send((0, _iframe2.default)(headHtml));
});

app.listen(_commander2.default.port, function (error) {
app.listen.apply(app, listenAddr.concat([function (error) {
if (error) {
throw error;
} else {
logger.info('\nReact Storybook started on => http://localhost:' + _commander2.default.port + '/ \n');
var address = 'http://' + (_commander2.default.host || 'localhost') + ':' + _commander2.default.port + '/';
logger.info('\nReact Storybook started on => ' + address + '\n');
}
});
}]));
12 changes: 8 additions & 4 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ if (!program.port) {
process.exit(-1);
}

if (!program.host) {
program.host = 'localhost';
// Used with `app.listen` below
const listenAddr = [program.port];

if (program.host) {
listenAddr.push(program.host);
}

const app = express();
Expand Down Expand Up @@ -69,10 +72,11 @@ app.get('/iframe.html', function (req, res) {
res.send(getIframeHtml(headHtml));
});

app.listen(program.port, program.host, function (error) {
app.listen(...listenAddr, function (error) {
if (error) {
throw error;
} else {
logger.info(`\nReact Storybook started on => http://${program.host}:${program.port}/ \n`);
const address = `http://${program.host || 'localhost'}:${program.port}/`;
logger.info(`\nReact Storybook started on => ${address}\n`);
}
});

0 comments on commit 464a463

Please sign in to comment.