const express = require('express')
const app = express()

var bodyParser = require('body-parser');
app.use(bodyParser.json())

//const puppeteer = require('puppeteer');
const puppeteer = require('puppeteer-extra');
const pluginStealth = require('puppeteer-extra-plugin-stealth');
puppeteer.use(pluginStealth())

const puppeteerCluster = require('./middleware/puppeteerCluster');
const { Cluster } = require('puppeteer-cluster');

(async () => {
    

    cluster = await Cluster.launch({
      concurrency: Cluster.CONCURRENCY_BROWSER,
      maxConcurrency: 6,
      //monitor: true,
      timeout: 20000,
      retryLimit: 2, 
      puppeteerOptions: {
        executablePath: '/usr/bin/google-chrome',
        args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'],
        ignoreDefaultArgs: ['--disable-extensions'],
        headless: 'new',
        env: {
          TZ: 'Europe/Paris'
        }
      },
      puppeteer: puppeteer
    });
    app.use(puppeteerCluster(cluster));

    // main routes    
    app.use('/api/sale', require('./routes/sale'));
    app.use('/api/lot', require('./routes/lot'));
    
  })();


module.exports = app