Skip to content

Commit

Permalink
feat: Add host and port arguments to dev command
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed Apr 9, 2019
1 parent d3734f8 commit e3d7a05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bin/pangolin-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ program
.command('dev')
.description('Start development server')
.option('-o, --open [browser]', 'Open in default or specific browser')
.option('--host <hostname>', 'Override the default localhost hostname')
.option('--port <port>', 'Override the default 8080 port')
.action(env => {
require('../lib/commands/dev')({
open: env.open
open: env.open,
host: env.host,
port: env.port
})
})

Expand Down
14 changes: 12 additions & 2 deletions lib/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ module.exports = async function (options) {
const context = process.cwd()
store.setup(context)

// Override host with CLI argument
if (options.host) {
store.state.config.devServer.host = options.host
}

// Override port with CLI argument
if (options.port) {
store.state.config.devServer.port = options.port
}

generateImports(context)

// Get free port for server
const serverPort = await getPort(store.state.config.devServer.port)
const serverHost = 'localhost'
const serverHost = store.state.config.devServer.host
const serverURL = `http://${serverHost}:${serverPort}`

// Create WebSocket communicate with Pangolin UI
Expand All @@ -43,7 +53,7 @@ module.exports = async function (options) {
path.join(__dirname, '../../ui/dist'),
path.join(context, 'src/public')
],
host: 'localhost',
host: serverHost,
hot: true,
quiet: true,
watchContentBase: true
Expand Down
8 changes: 8 additions & 0 deletions lib/utils/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ module.exports = (context) => {
config.devServer = {}
}

if (process.env.PANGOLIN_HOST) {
config.devServer.host = process.env.PANGOLIN_HOST
}

if (!config.devServer.host) {
config.devServer.host = 'localhost'
}

if (process.env.PANGOLIN_PORT) {
config.devServer.port = parseInt(process.env.PANGOLIN_PORT)
}
Expand Down

0 comments on commit e3d7a05

Please sign in to comment.