-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (40 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const puppeteer = require('puppeteer');
const app = express();
app.get('/screenshot', async (req, res) => {
let url = 'https://adobe-commerce-tester.freetls.fastly.net/adobe-commerce-tester/';
if (req.query.url) {
url = req.query.url;
}
if (!url) {
return res.status(400).send('Missing URL parameter');
}
let screenshot = 'Not yet';
(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox'],
headless: true
});
const page = await browser.newPage();
await page.goto(url, {
waitUntil: "networkidle0"
}).catch((err) => {
console.log(err);
});
page.setViewport({width: 800, height: 400});
screenshot = await page.screenshot({ fullPage: true });
await browser.close();
res.set('Content-Type', 'image/png');
res.send(screenshot);
})();
});
app.get('/ping', async (req, res) => {
var obj = {};
obj.status = "ok";
obj.envname = process.env.ENVIRONMENT_NAME;
obj.region = process.env.REGION_NAME;
res.json(obj);
});
app.listen(3000, () => {
console.log('Server listening on port 3000');
});