forked from wildsurfer/prerender
-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
executable file
·57 lines (45 loc) · 1.81 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
var prerender = require('./lib');
// const axios = require('axios');
// const { fork, spawn } = require('child_process');
// const options = {
// slient:true,
// detached:true,
// stdio: 'ignore'
// };
// child = spawn('/usr/bin/chromium-browser', ['--disable-web-security', '--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars', '--disable-dev-shm-usage'], options);
// child.unref();
var server = prerender({
chromeLocation: '/usr/bin/chromium-browser',
logRequests: true,
chromeFlags: ['--disable-web-security', '--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars', '--disable-dev-shm-usage']
});
server.use(prerender.sendPrerenderHeader());
server.use(prerender.blockResources());
server.use(prerender.removeScriptTags());
server.use(prerender.httpHeaders());
server.use(require('prerender-memory-cache'))
server.start();
const languages = ["en", "de","fr","es","pt","it","tr","ru","ja","pl"]
const makeRequest = async (language) => {
const url = `http://localhost:3000/http://web-service-main:8080/${language}/`;
return axios.get(url)
.then((response) => {
const statusCode = response.status;
console.log(`Status code for ${language}: ${statusCode}`);
})
.catch((error) => {
console.error(`Error making request for ${language}:`, error);
});
}
// the code here makes the container raise an exception in the websockets of Chrome
// setTimeout(async () => {
// const requestPromises = languages.map((language) => makeRequest(language));
// await Promise.all(requestPromises)
// .then(() => {
// console.log('All languages rendered.');
// })
// .catch((error) => {
// console.error('Error executing requests:', error);
// });
// }, 5000);