Skip to content

Commit

Permalink
Cleanup server
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Brown committed Nov 6, 2024
1 parent 1a1f8e6 commit bbc3acc
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ export const GET: RequestHandler = async ({ url, params }) => {
}

// see hooks.server.ts for configuration details
const browser = await PuppeteerManager.launch()
const browser = await PuppeteerManager.launch();

console.time('render2')
// Set up the page
page = await browser.newPage();
await page.setViewport({
Expand All @@ -75,9 +74,7 @@ export const GET: RequestHandler = async ({ url, params }) => {

// Navigate to the page rendering the button
await page.goto(imageUrl);
console.timeEnd('render2')

console.time('render3')
// Get the button
const selector = '.support-button';
const element = await page.waitForSelector(selector);
Expand All @@ -86,8 +83,7 @@ export const GET: RequestHandler = async ({ url, params }) => {
if (!element) {
return error(500);
}
console.timeEnd('render3')
console.time('render4')

// Take a screenshot of the button
const imageBuffer = await element.screenshot({ omitBackground: true });
// Cache the result
Expand All @@ -96,7 +92,6 @@ export const GET: RequestHandler = async ({ url, params }) => {
redis?.set(cacheKey, imageBase64, {
...(cacheExpiration !== Infinity && { EX: cacheExpiration }),
});
console.timeEnd('render4')

return new Response(imageBuffer, {
status: 200,
Expand Down

0 comments on commit bbc3acc

Please sign in to comment.