Skip to content

Commit

Permalink
fix: ignore falsy config.port option
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 8, 2022
1 parent 30a0f1f commit ca34365
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ function log (...args) {
console.log('[get-port]', ...args)
}

export async function getPort (config?: GetPortInput): Promise<PortNumber> {
export async function getPort (config: GetPortInput = {}): Promise<PortNumber> {
if (typeof config === 'number' || typeof config === 'string') {
config = { port: parseInt(config + '') }
config = { port: parseInt(config + '') || 0 }
}

const options = {
name: 'default',
random: false,
port: parseInt(process.env.PORT || '') || 3000,
ports: [],
portRange: [],
alternativePortRange: [3000, 3100],
host: undefined,
memoName: 'port',
verbose: false,
...config
...config,
port: parseInt(process.env.PORT || '') || config.port || 3000
} as GetPortOptions

if (options.random) {
Expand Down

0 comments on commit ca34365

Please sign in to comment.