Last active
July 9, 2020 16:40
-
-
Save mhsattarian/447f6d0105e6652f344a01879e16e083 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Code from https://github.com/leighhalliday/generate-og-image/blob/master/src/chromium.ts | |
// and https://github.com/wesbos/wesbos/blob/master/functions/ogimage/ogimage.js | |
// and thanks wes.bos for the video on this at https://youtu.be/A0Ww-SU7K5E | |
exports.handler = async (event, context, callback) => { | |
const url = event.queryStringParameters.url; | |
const r = await fetch( | |
`https://publish.twitter.com/oembed?url=${url}&hide_thread=true` | |
).then((r) => r.json()); | |
try { | |
const isDev = process.env.CHROME === "local" ? true : false; | |
const photoBuffer = await getScreenshot(html, isDev); | |
return { | |
statusCode: 200, | |
body: photoBuffer.toString("base64"), | |
isBase64Encoded: true, | |
}; | |
} catch (err) { | |
callback(err, null); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment