forked from tvanro/prerender-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (28 loc) · 1.03 KB
/
server.js
File metadata and controls
35 lines (28 loc) · 1.03 KB
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
const prerender = require('prerender');
const prMemoryCache = require('prerender-memory-cache');
const chromeFlags = ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars', '--disable-dev-shm-usage']
if (process.env.PROXY_SERVER) {
chromeFlags.push(`--proxy-server=${process.env.PROXY_SERVER}`)
}
const server = prerender({
chromeFlags,
forwardHeaders: true,
chromeLocation: '/usr/bin/chromium-browser'
});
const memCache = Number(process.env.MEMORY_CACHE) || 0;
if (memCache === 1) {
server.use(prMemoryCache);
}
server.use({
requestReceived: (req, res, next) => {
const ALLOWED_DOMAINS = (process.env.ALLOWED_DOMAINS && process.env.ALLOWED_DOMAINS.split(',')) || [];
if (ALLOWED_DOMAINS.some((domain) => new RegExp(`^([a-z]+\.)?${domain.replace('.', '\.')}$`).test(domain))) {
next();
} else {
res.send(404);
}
}
});
server.use(prerender.httpHeaders());
server.use(prerender.removeScriptTags());
server.start();