Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use IPv6 by default, add
useIPv6
option (#12)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
e9f4118
commit 894100d
Showing
5 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
'use strict'; | ||
const got = require('got'); | ||
|
||
module.exports = async options => { | ||
options = { | ||
endpoint: 'https://api.ipify.org', | ||
...options | ||
}; | ||
const IPIFY_ENDPOINT_IPV4 = 'https://api.ipify.org'; | ||
const IPIFY_ENDPOINT_IPV6 = 'https://api6.ipify.org'; | ||
|
||
const {body} = await got(options.endpoint); | ||
module.exports = async ({useIPv6 = true, endpoint} = {}) => { | ||
if (endpoint === undefined) { | ||
endpoint = useIPv6 ? IPIFY_ENDPOINT_IPV6 : IPIFY_ENDPOINT_IPV4; | ||
} | ||
|
||
const {body} = await got(endpoint); | ||
return body; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters