Skip to content

Instantly share code, notes, and snippets.

@mhsattarian
Last active July 9, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhsattarian/447f6d0105e6652f344a01879e16e083 to your computer and use it in GitHub Desktop.
Save mhsattarian/447f6d0105e6652f344a01879e16e083 to your computer and use it in GitHub Desktop.
// 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