Skip to content

Commit

Permalink
启动时自动打开浏览器
Browse files Browse the repository at this point in the history
  • Loading branch information
antife-yinyue committed Jul 30, 2014
1 parent a96547e commit c821899
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('fs');
var URL = require('url');
var path = require('path');
var exec = require('child_process').exec;

var mimes = require('./mime.json');
var $ = require('./helper');
Expand Down Expand Up @@ -166,10 +167,17 @@ function startApp(port, dir, host, argvObj) {
return app.on('listening', function() {
var server = app.address();
var address = server.address === '0.0.0.0' ? '127.0.0.1' : server.address;
var url = ' http://' + address + ':' + server.port

console.log('ppt directory:'.cyan + ' ' + pptDir);
console.log('assets directory:'.cyan + ' '+staticDir);
console.log('nodeppt server started:'.cyan + (' http://'+address + ':' + server.port).yellow);
console.log('nodeppt server started:'.cyan + url.yellow);

if (process.platform === 'win32') {
exec('start' + url);
} else {
exec('open' + url);
}
}).on('error', function(e) {
if (e.code === 'EADDRINUSE' || e.code === 'EACCES') {
console.log('ERROR: '.red + 'port ' + port + ' is in use!');
Expand Down

0 comments on commit c821899

Please sign in to comment.