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

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');