2021-07-17 03:01:06 +00:00
|
|
|
const https = require('https')
|
|
|
|
|
|
|
|
async function httpGet(url) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
https.get(url, (response) => {
|
2021-08-02 15:42:45 +00:00
|
|
|
const chunks = []
|
|
|
|
response.on('data', (d) => chunks.push(d))
|
|
|
|
response.on('end', () => resolve(chunks.join('')))
|
2021-07-17 03:01:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const handler = async (event) => {
|
|
|
|
try {
|
|
|
|
const url = event.queryStringParameters.url
|
|
|
|
const proxiedResponse = await httpGet(url)
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
body: String(proxiedResponse),
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return { statusCode: 500, body: error.toString() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { handler }
|