-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.cjs
44 lines (33 loc) · 983 Bytes
/
server.cjs
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
const puppeteer = require('puppeteer');
const fileName = 'programme-tz';
const express = require('express');
const app = express();
const path = require('path');
const morgan = require('morgan');
const httpPort = 1337;
app.use(morgan('dev'));
app.use(express.static(__dirname + '/dist'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
async function init() {
const server = app.listen(httpPort);
await generate(fileName, 'fr', httpPort);
server.close();
}
async function generate(fileName, locale, httpPort) {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-web-security', `--user-data-dir=data`]
});
const page = await browser.newPage();
await page.goto(`http://localhost:${httpPort}`, {
waitUntil: 'networkidle2'
});
await page.setViewport({
width: 1240,
height: 1400
});
await page.screenshot({ path: 'tz-programme.png' })
await browser.close();
}
init();