Add open in browser functionality (#643)

This commit is contained in:
Yangshun Tay 2018-05-07 09:46:14 -07:00 committed by Joel Marcey
parent 432bdffb22
commit 1a6f2fc51c
5 changed files with 30 additions and 2 deletions

View file

@ -24,6 +24,7 @@ const tcpPortUsed = require('tcp-port-used');
// initial check that required files are present
const chalk = require('chalk');
const fs = require('fs');
const opn = require('opn');
const CWD = process.cwd();
if (!fs.existsSync(CWD + '/siteConfig.js')) {
@ -59,10 +60,12 @@ function checkPort() {
numAttempts += 1;
checkPort();
} else {
console.log('Starting Docusaurus server on port ' + port + '...');
// start local server on specified port
const server = require('./server/server.js');
server(port);
const host = `http://localhost:${port}`;
console.log(`Starting Docusaurus server on ${host}`);
opn(host);
}
})
.catch(function(ex) {