format project
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
// Got the proof of concept working locally, but even though chrome-aws-lambda is supposed to fit into a AWS lambda it did not for me
|
||||
// in the mean time this is causing builds to fail so moved it out here.
|
||||
import { builder } from '@netlify/functions'
|
||||
const { headless, executablePath, puppeteer} = require('chrome-aws-lambda')
|
||||
const { headless, executablePath, puppeteer } = require('chrome-aws-lambda')
|
||||
|
||||
const captureWidth = 1200
|
||||
const captureHeight = 630
|
||||
const clipY = 0
|
||||
|
||||
async function unwrappedHandler (event, context) {
|
||||
let path = event.path
|
||||
async function unwrappedHandler(event, context) {
|
||||
const path = event.path
|
||||
.replace(/.+\/og-image-generator/, '')
|
||||
.replace(/\/og-image-.+\.jpg/, '')
|
||||
|
||||
@@ -19,17 +19,23 @@ async function unwrappedHandler (event, context) {
|
||||
executablePath: process.env.URL?.includes('localhost')
|
||||
? null
|
||||
: await executablePath,
|
||||
args: ['--no-sandbox','--disable-web-security','--disable-gpu', '--hide-scrollbars', '--disable-setuid-sandbox'],
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-web-security',
|
||||
'--disable-gpu',
|
||||
'--hide-scrollbars',
|
||||
'--disable-setuid-sandbox',
|
||||
],
|
||||
// args: chromium.args,
|
||||
defaultViewport: {
|
||||
width: captureWidth,
|
||||
height: captureHeight + clipY
|
||||
height: captureHeight + clipY,
|
||||
},
|
||||
headless: headless
|
||||
headless: headless,
|
||||
})
|
||||
const page = await browser.newPage()
|
||||
|
||||
await page.goto(url, {"waitUntil" : "networkidle0"});
|
||||
await page.goto(url, { waitUntil: 'networkidle0' })
|
||||
|
||||
const screenshot = await page.screenshot({
|
||||
type: 'jpeg',
|
||||
@@ -40,8 +46,8 @@ async function unwrappedHandler (event, context) {
|
||||
x: 0,
|
||||
y: clipY,
|
||||
width: captureWidth,
|
||||
height: captureHeight
|
||||
}
|
||||
height: captureHeight,
|
||||
},
|
||||
})
|
||||
|
||||
await browser.close()
|
||||
@@ -55,10 +61,10 @@ async function unwrappedHandler (event, context) {
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'image/jpg'
|
||||
'Content-Type': 'image/jpg',
|
||||
},
|
||||
body: screenshot,
|
||||
isBase64Encoded: true
|
||||
isBase64Encoded: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user