Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Change server.listen default address
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Feb 22, 2023
1 parent 547ceb6 commit f248b47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions docs/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ Example:
`listen(port, [host], [callback])`

Begin accepting connections on the specified port and host. If the host is
omitted, the server will accept connections directed to any IPv4 address
(INADDR\_ANY).
omitted, the server will accept connections directed to the IPv4 address
`127.0.0.1`. To listen on any other address, supply said address as the `host`
parameter. For example, to listen on all available IPv6 addresses supply
`::` as the `host` (note, this _may_ also result in listening on all
available IPv4 addresses, depending on operating system behavior).

We highly recommend being as explicit as possible with the `host` parameter.
Listening on all available addresses (through `::` or `0.0.0.0`) can lead
to potential security issues.

This function is asynchronous. The last parameter callback will be called when
the server has been bound.
Expand Down
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,13 @@ Server.prototype.after = function () {
})
}

// All these just reexpose the requisite net.Server APIs
// All these just re-expose the requisite net.Server APIs
Server.prototype.listen = function (port, host, callback) {
if (typeof (port) !== 'number' && typeof (port) !== 'string') { throw new TypeError('port (number or path) required') }

if (typeof (host) === 'function') {
callback = host
host = '0.0.0.0'
host = '127.0.0.1'
}
if (typeof (port) === 'string' && /^[0-9]+$/.test(port)) {
// Disambiguate between string ports and file paths
Expand Down

0 comments on commit f248b47

Please sign in to comment.