This commit is contained in:
spiduler
2020-10-20 08:12:48 +09:00
parent 645ea995d6
commit 7de1f460f0
3 changed files with 35 additions and 63 deletions

View File

@@ -63,22 +63,12 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
* request handler
*/
app.post('/', async (req, res, next) => {
const requestPage = () => browser.get(req.body.uri, req.body.waitElement).then(html => res.send(html)).catch(e => {
if(e instanceof NoSuchSessionError) {
browser.reset()
browser.get(req.body).then(html => res.send(html)).catch(e => {
if(e instanceof NoSuchSessionError) {
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
}else {
logger.error({ reason: e.message, url: req.url }, 'Browser error occured')
}
res.status(500).send({ code: 500, message: e.message })
// browser.close().then(() => e instanceof puppeteerErrors.TimeoutError ? setTimeout(() => requestPage(), 3000) : res.status(500).send(e.message))
})
requestPage()
})
app.get('/restart', (req, res, next) => {
// browser.close().then(() => {
// res.json({message: 'Browser closed and lanuch with new request'})
// })
process.exit()
})