devusman commited on
Commit
f46a3f8
·
1 Parent(s): 461df32
Files changed (2) hide show
  1. Dockerfile +26 -9
  2. server.js +14 -2
Dockerfile CHANGED
@@ -4,10 +4,16 @@ FROM node:18-slim
4
  # Set working directory
5
  WORKDIR /app
6
 
7
- # Install dependencies for Puppeteer (Chromium needs these)
8
  RUN apt-get update && apt-get install -y \
9
  wget \
 
10
  ca-certificates \
 
 
 
 
 
11
  fonts-liberation \
12
  libasound2 \
13
  libatk1.0-0 \
@@ -41,19 +47,30 @@ RUN apt-get update && apt-get install -y \
41
  xdg-utils \
42
  && rm -rf /var/lib/apt/lists/*
43
 
44
- # Copy package.json and install dependencies
45
  COPY package*.json ./
 
 
46
  RUN npm install --omit=dev
47
 
48
- # Copy the rest of the app
49
  COPY . .
50
 
51
- # Expose port (Spaces will map automatically)
52
- EXPOSE 7860
 
 
 
53
 
54
- # Puppeteer: tell it to use the system Chromium
55
- ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
56
  ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
 
 
 
 
 
 
 
57
 
58
- # Start the server
59
- CMD ["npm", "start"]
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install Chrome/Chromium and dependencies
8
  RUN apt-get update && apt-get install -y \
9
  wget \
10
+ gnupg \
11
  ca-certificates \
12
+ && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
13
+ && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
14
+ && apt-get update \
15
+ && apt-get install -y \
16
+ google-chrome-stable \
17
  fonts-liberation \
18
  libasound2 \
19
  libatk1.0-0 \
 
47
  xdg-utils \
48
  && rm -rf /var/lib/apt/lists/*
49
 
50
+ # Create package.json
51
  COPY package*.json ./
52
+
53
+ # Install Node.js dependencies
54
  RUN npm install --omit=dev
55
 
56
+ # Copy application files
57
  COPY . .
58
 
59
+ # Create a non-root user for security
60
+ RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
61
+ && mkdir -p /home/pptruser/Downloads \
62
+ && chown -R pptruser:pptruser /home/pptruser \
63
+ && chown -R pptruser:pptruser /app
64
 
65
+ # Set environment variables
 
66
  ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
67
+ ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
68
+
69
+ # Expose port
70
+ EXPOSE 7860
71
+
72
+ # Switch to non-root user
73
+ USER pptruser
74
 
75
+ # Start the application
76
+ CMD ["npm", "start"]
server.js CHANGED
@@ -340,8 +340,9 @@ const studocuDownloader = async (url, options = {}) => {
340
  let browser;
341
  try {
342
  console.log("🚀 Launching browser with stealth configuration...");
 
343
  browser = await puppeteer.launch({
344
- headless: true,
345
  args: [
346
  '--no-sandbox',
347
  '--disable-setuid-sandbox',
@@ -359,9 +360,20 @@ const studocuDownloader = async (url, options = {}) => {
359
  '--disable-web-security',
360
  '--disable-features=site-per-process',
361
  '--disable-blink-features=AutomationControlled',
362
- '--disable-extensions'
 
 
 
 
 
 
 
 
 
 
363
  ],
364
  timeout: 300000,
 
365
  });
366
 
367
  const page = await browser.newPage();
 
340
  let browser;
341
  try {
342
  console.log("🚀 Launching browser with stealth configuration...");
343
+ // Replace this part in your server.js (around line 343)
344
  browser = await puppeteer.launch({
345
+ headless: "new", // Use new headless mode
346
  args: [
347
  '--no-sandbox',
348
  '--disable-setuid-sandbox',
 
360
  '--disable-web-security',
361
  '--disable-features=site-per-process',
362
  '--disable-blink-features=AutomationControlled',
363
+ '--disable-extensions',
364
+ '--single-process', // Important for containers
365
+ '--disable-background-tasks',
366
+ '--disable-default-apps',
367
+ '--disable-sync',
368
+ '--metrics-recording-only',
369
+ '--no-default-browser-check',
370
+ '--no-pings',
371
+ '--password-store=basic',
372
+ '--use-mock-keychain',
373
+ '--disable-gpu-sandbox'
374
  ],
375
  timeout: 300000,
376
+ executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || '/usr/bin/google-chrome-stable'
377
  });
378
 
379
  const page = await browser.newPage();