Kyouka commited on
Commit
edb8775
·
verified ·
1 Parent(s): 8e119b9

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +23 -10
index.js CHANGED
@@ -291,11 +291,18 @@ app.get('/dongo', async (req, res) => {
291
  });
292
 
293
  app.get('/fetch-page', async (req, res) => {
 
 
 
 
 
 
294
  const browser = await playwright.chromium.launch({
295
- headless: true,
296
- executablePath: '/usr/bin/chromium',
297
- args: ['--no-sandbox']
298
- })
 
299
  const context = await browser.newContext({
300
  extraHTTPHeaders: {
301
  'accept': '*/*',
@@ -314,14 +321,20 @@ app.get('/fetch-page', async (req, res) => {
314
  }
315
  });
316
 
317
- const page = await context.newPage();
318
- await page.goto('https://doujindesu.tv');
319
-
320
- const content = await page.content(); // Get the page content as HTML
321
 
322
- await browser.close();
 
323
 
324
- res.send(content); // Send the page content as response
 
 
 
 
 
 
325
  });
326
 
327
  const PORT = process.env.PORT || 7860
 
291
  });
292
 
293
  app.get('/fetch-page', async (req, res) => {
294
+ const targetUrl = req.query.url;
295
+
296
+ if (!targetUrl) {
297
+ return res.status(400).json({ error: 'Parameter "url" dibutuhkan' });
298
+ }
299
+
300
  const browser = await playwright.chromium.launch({
301
+ headless: true,
302
+ executablePath: '/usr/bin/chromium', // pastikan path ini benar di server kamu
303
+ args: ['--no-sandbox']
304
+ });
305
+
306
  const context = await browser.newContext({
307
  extraHTTPHeaders: {
308
  'accept': '*/*',
 
321
  }
322
  });
323
 
324
+ try {
325
+ const page = await context.newPage();
326
+ await page.goto(targetUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
 
327
 
328
+ // Tunggu ekstra jika perlu ngelewatin challenge
329
+ await page.waitForTimeout(8000);
330
 
331
+ const content = await page.content();
332
+ res.send(content);
333
+ } catch (err) {
334
+ res.status(500).json({ error: 'Gagal fetch halaman', detail: err.message });
335
+ } finally {
336
+ await browser.close();
337
+ }
338
  });
339
 
340
  const PORT = process.env.PORT || 7860