Skip to content

Commit 33c1019

Browse files
add: h & w as query params with fallback case
1 parent 719650c commit 33c1019

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/pages/api/generate.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ const serverOptions = {
2525
}
2626

2727
export const GET: APIRoute = async ({ url }) => {
28-
const isDev = url.searchParams.get('dev') === 'true'
28+
const { isDev, height, width } = {
29+
isDev: url.searchParams.get('dev') === 'true',
30+
height: url.searchParams.get('h'),
31+
width: url.searchParams.get('w')
32+
};
2933
const options = isDev ? Localoptions : serverOptions
3034

3135
try {
@@ -46,8 +50,8 @@ export const GET: APIRoute = async ({ url }) => {
4650

4751
// set the viewport size
4852
await page.setViewport({
49-
width: 1920,
50-
height: 1080,
53+
width: width ? Math.abs(parseInt(width)) : 1920,
54+
height: height ? Math.abs(parseInt(height)) : 1080,
5155
deviceScaleFactor: 1,
5256
})
5357

0 commit comments

Comments
 (0)