Skip to content

Commit

Permalink
Added type and range validation for port (#52)
Browse files Browse the repository at this point in the history
* Add port type and range validation to micro-dev.

* Correct syntax
  • Loading branch information
rapzo authored and leo committed Jan 4, 2018
1 parent 756f52c commit 10026cb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/serve.js
Expand Up @@ -22,8 +22,13 @@ module.exports = async (file, flags, restarting) => {
: log(getModule(file), flags.limit)
const server = serve(module)

// `3000` is the default port
let port = ~~flags.port
const { isNaN } = Number
let port = Number(flags.port)

if (isNaN(port) || (!isNaN(port) && (port < 1 || port >= 2 ** 16))) {

This comment has been minimized.

Copy link
@timneutkens

timneutkens Jan 4, 2018

Member

We'll want to use Math.pow here like in micro itself.

console.error(`Port option must be a number. Supplied: ${flags.port}`)
process.exit(1)
}

// Check if the specified port is already in use (if none
// is specified, the default one will be checked)
Expand Down

0 comments on commit 10026cb

Please sign in to comment.