Created
July 25, 2020 03:34
-
-
Save mikeal/3e7916662c0389ca8f3fc37925bcf11b to your computer and use it in GitHub Desktop.
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
const publicIp = require('public-ip') | |
const bent = require('bent') | |
const get = bent('json', 'https://my-lambda-url') | |
exports.handler = async function http (req) { | |
let { retries, ips } = req.queryStringParameters | |
const ip = await publicIp.v4() | |
if (ips) ips = ips.split(',') | |
else ips = [] | |
ips.push(ip) | |
retries = parseInt(retries) | |
if (retries) { | |
ips = await get(`?retries=${retries-1}&ips=${ips.join(',')}`) | |
} | |
return { | |
headers: { | |
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0', | |
'content-type': 'application/json' | |
}, | |
body: JSON.stringify(ips, null, 2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment