Created
December 14, 2017 17:59
-
-
Save RomanGorbatko/b13d4a7310464e7b9dddf9dc440235a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
// const moment = require('moment'); | |
// const uuidv4 = require('uuid/v4'); | |
const fs = require('fs'); | |
const process = require('process'); | |
const puppeteer = require('puppeteer'); | |
const app = express(); | |
import Debug from 'debug'; | |
import Facebook from 'src/facebook/index'; | |
const port = 3004; | |
let browser = null; | |
/* Init debug instance */ | |
const _d = new Debug('app:crawler'); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
/** | |
* Wrapper for async/wait routes | |
* | |
* @param fn | |
* @returns {function(*=, *=, *=)} | |
*/ | |
function asyncWrap(fn) { | |
return (req, res, next) => { | |
fn(req, res, next).catch(next); | |
}; | |
} | |
/** | |
* | |
*/ | |
app.post('/run', asyncWrap(async (req, res) => { | |
let body = req.body | |
console.log(body) | |
const facebook = new Facebook(browser) | |
facebook.setRequestBody(body) | |
await facebook.newTab() | |
// | |
// await facebook.closeTab() | |
console.log('closeTab'); | |
return res.send(photos); | |
})); | |
const server = app.listen(port, () => { | |
(async () => { | |
try { | |
console.log('Open Browser'); | |
browser = await puppeteer.launch({ | |
headless: false, | |
// headless: true, | |
// dumpio: true, | |
timeout: 24000000, | |
args: [ | |
'--disable-notifications', | |
'--disable-rtc-smoothness-algorithm', | |
'--enforce-webrtc-ip-permission-check', | |
'--no-sandbox', | |
'--disable-setuid-sandbox', | |
'--proxy-server=213.184.97.219:56847' | |
] | |
}); | |
} catch (e) { | |
console.log(e); | |
} | |
process.on('exit', () => server.stop()) | |
})(); | |
console.log('We are live on ' + port); | |
}); | |
// increase the timeout to 4 minutes | |
server.timeout = 24000000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment