This commit is contained in:
ld3zian 2025-05-03 12:28:50 -07:00
parent 94c02124f2
commit 859f839b66
3 changed files with 54 additions and 5 deletions

32
package-lock.json generated
View file

@ -12,6 +12,7 @@
"@astrojs/tailwind": "^6.0.2",
"@astrojs/vercel": "^8.1.4",
"@floating-ui/dom": "^1.6.13",
"@sparticuz/chromium": "^133.0.0",
"@types/node": "^22.15.3",
"@vercel/analytics": "^1.5.0",
"astro": "^5.7.10",
@ -1474,6 +1475,18 @@
"resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz",
"integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg=="
},
"node_modules/@sparticuz/chromium": {
"version": "133.0.0",
"resolved": "https://registry.npmjs.org/@sparticuz/chromium/-/chromium-133.0.0.tgz",
"integrity": "sha512-wioNxMtSxRI+Y6ymc/UFPX9lY7A1SDgBezjFITH6arwe5CONfWosNDGpgflUGYajxxGktb1k3kjJ83jWzbccBw==",
"dependencies": {
"follow-redirects": "^1.15.9",
"tar-fs": "^3.0.8"
},
"engines": {
"node": ">= 16"
}
},
"node_modules/@swc/helpers": {
"version": "0.5.17",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.17.tgz",
@ -3313,6 +3326,25 @@
"node": ">=8"
}
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/fontkit": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-2.0.4.tgz",

View file

@ -15,6 +15,7 @@
"@astrojs/tailwind": "^6.0.2",
"@astrojs/vercel": "^8.1.4",
"@floating-ui/dom": "^1.6.13",
"@sparticuz/chromium": "^133.0.0",
"@types/node": "^22.15.3",
"@vercel/analytics": "^1.5.0",
"astro": "^5.7.10",

View file

@ -1,7 +1,9 @@
import type { APIRoute } from "astro";
import chromium from 'chrome-aws-lambda';
import puppeteerCore from 'puppeteer-core';
// Import @sparticuz/chromium for better serverless compatibility
import chromium from '@sparticuz/chromium';
// Check if running on Vercel
const IS_VERCEL = process.env.VERCEL === '1' || process.env.VERCEL === 'true';
@ -16,13 +18,17 @@ async function scrapeComicList(userId: string, limit: number = 10): Promise<stri
let browser;
if (IS_VERCEL) {
// Use chrome-aws-lambda for Vercel environment
console.log('Running on Vercel - using chrome-aws-lambda');
// Use @sparticuz/chromium which is optimized for serverless environments
console.log('Running on Vercel - using @sparticuz/chromium with serverless settings');
// Configure @sparticuz/chromium for Vercel
await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf');
browser = await puppeteerCore.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
executablePath: await chromium.executablePath(), // Note: this is now a function call
headless: true, // Always use headless mode in serverless environment
ignoreHTTPSErrors: true,
});
} else {
@ -173,6 +179,16 @@ export const GET: APIRoute = async ({ request }) => {
});
try {
// Log environment information for debugging
console.log(`Environment: ${IS_VERCEL ? 'Vercel' : 'Local'}`);
if (IS_VERCEL) {
try {
console.log('Chrome executable path:', await chromium.executablePath());
console.log('Chrome args:', chromium.args);
} catch (e) {
console.log('Error getting Chrome executable path:', e);
}
}
const url = new URL(request.url);
const userId = url.searchParams.get('userId');