Skip to content

Commit d378ca8

Browse files
committed
wip
1 parent f3b87bf commit d378ca8

File tree

13 files changed

+1942
-6526
lines changed

13 files changed

+1942
-6526
lines changed

.astro/types.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

astro.config.mjs

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/index.test.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

example/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
"dependencies": {
1919
"@devprotocol/util-ts": "^4.0.0",
2020
"@sparticuz/chromium-min": "^130.0.0",
21-
"astro": "5.1.10",
22-
"astro-aws-amplify": "^0.1.0",
21+
"aws-lambda": "^1.0.7",
2322
"puppeteer-core": "23.6.0"
2423
},
2524
"devDependencies": {
26-
"@astrojs/netlify": "^6.1.0",
27-
"@astrojs/vercel": "8.0.4",
2825
"@eslint/js": "^9.12.0",
26+
"@rollup/plugin-commonjs": "^28.0.2",
27+
"@rollup/plugin-json": "^6.1.0",
28+
"@rollup/plugin-node-resolve": "^16.0.0",
29+
"@rollup/plugin-typescript": "^12.1.2",
30+
"@types/aws-lambda": "^8.10.147",
2931
"@types/dotenv": "8.2.3",
3032
"@types/eslint-config-prettier": "^6.11.3",
3133
"@types/eslint__js": "^8.42.3",
@@ -38,9 +40,9 @@
3840
"husky": "9.1.6",
3941
"prettier": "3.3.3",
4042
"rimraf": "6.0.1",
43+
"rollup": "^4.32.1",
4144
"typescript": "5.6.3",
42-
"typescript-eslint": "^8.9.0",
43-
"vitest": "^2.1.3"
45+
"typescript-eslint": "^8.9.0"
4446
},
4547
"repository": "git+https://github.com/dev-protocol/template-repos-ts.git",
4648
"bugs": {

rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import typescript from '@rollup/plugin-typescript'
2+
import { nodeResolve } from '@rollup/plugin-node-resolve'
3+
import commonjs from '@rollup/plugin-commonjs'
4+
import json from '@rollup/plugin-json'
5+
6+
export default {
7+
input: 'src/index.ts',
8+
output: {
9+
dir: 'dist',
10+
format: 'es',
11+
},
12+
plugins: [typescript(), commonjs(), nodeResolve(), json()],
13+
}

src/env.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/pages/api/generate.ts renamed to src/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable functional/no-expression-statements */
2-
import { type APIRoute } from 'astro'
2+
import type { Handler } from 'aws-lambda'
3+
import type { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda'
34
import chromium from '@sparticuz/chromium-min'
4-
import { Chromium } from '../../libs/chromium.ts'
5+
import { Chromium } from './libs/chromium.js'
56
import type { PuppeteerLifeCycleEvent } from 'puppeteer-core'
67

78
const exePath =
@@ -37,7 +38,10 @@ const puppeteerLifeCycleEvents = [
3738
'networkidle2',
3839
] satisfies PuppeteerLifeCycleEvent[]
3940

40-
export const GET: APIRoute = async ({ url }) => {
41+
export const handler: Handler = async (
42+
event: APIGatewayEvent,
43+
): Promise<APIGatewayProxyResult> => {
44+
const url = new URL(event.path)
4145
const { isDev, height, width, cacheControl, gotoThenWaitUntil } = {
4246
isDev: url.searchParams.get('dev') === 'true',
4347
height: url.searchParams.get('h'),
@@ -52,12 +56,12 @@ export const GET: APIRoute = async ({ url }) => {
5256
const targetUrl = url.searchParams.get('src')
5357

5458
if (!targetUrl) {
55-
return new Response('URL query parameter is required', { status: 400 })
59+
return { statusCode: 404, body: 'URL query parameter is required' }
5660
}
5761

5862
// Validate that the URL starts with http or https
5963
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
60-
return new Response('Invalid URL format', { status: 400 })
64+
return { statusCode: 400, body: 'Invalid URL format' }
6165
}
6266

6367
const browser = await Chromium.getInstance(options)
@@ -96,16 +100,20 @@ export const GET: APIRoute = async ({ url }) => {
96100
// await browser.close()
97101

98102
// Return the PNG image as the response
99-
return new Response(file, {
100-
status: 200,
103+
return {
104+
statusCode: 200,
105+
body: Buffer.from(file).toString('base64'),
101106
headers: {
102107
'Content-Type': 'image/png',
103108
'access-control-allow-origin': '*',
104109
'cache-control': cacheControl ?? `public, max-age=31536000`,
105110
},
106-
})
111+
} satisfies APIGatewayProxyResult
107112
} catch (error) {
108113
console.error('Error capturing screenshot:', error)
109-
return new Response('Internal Server Error', { status: 500 })
114+
return {
115+
statusCode: 500,
116+
body: 'Internal Server Error',
117+
}
110118
}
111119
}

src/pages/index.astro

Lines changed: 0 additions & 16 deletions
This file was deleted.

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "astro/tsconfigs/strict",
32
"compilerOptions": {
43
"module": "nodenext",
54
"lib": ["esnext"],

0 commit comments

Comments
 (0)