Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.