Skip to content

Commit

Permalink
Merge pull request #13 from faergeek/master
Browse files Browse the repository at this point in the history
Error handling for "open" and better default options
  • Loading branch information
avevlad committed Feb 10, 2014
2 parents 6136af8 + 44a72d9 commit 5e0ecdb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = {
if (!o.livereload) o.livereload = false;
if (o.open) {
if (typeof o.open == 'boolean') o.open = {};
if (!o.open.file) o.open.file = 'index.html';
if (!o.open.browser) o.open.browser = 'chrome';
if (!o.open.file) o.open.file = '';
if (!o.open.browser) o.open.browser = undefined;
}
if (o.livereload) {
if (typeof o.livereload == 'boolean') o.livereload = {};
Expand All @@ -41,10 +41,19 @@ module.exports = {
server
.listen(o.port)
.on('listening', function() {
var url, browsername;

util.log(util.colors.green('Server started on ' + o.port + ' port'));
if (o.open) {
open('http://localhost:' + o.port + '/' + o.open.file, o.open.browser);
util.log(util.colors.green('Opened ' + o.open.file + ' in ' + o.open.browser));
url = 'http://localhost:' + o.port + '/' + o.open.file;

if (o.open.browser) browsername = o.open.browser;
else browsername = 'default browser';

open(url, o.open.browser, function(error) {
if (error) util.log(util.colors.red(error));
else util.log(util.colors.green('Opened ' + url + ' in ' + browsername));
});
}
})
};
Expand Down

0 comments on commit 5e0ecdb

Please sign in to comment.