-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
54 lines (48 loc) · 1.43 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
const express = require('express'),
path = require('path'),
rendertron = require('rendertron-middleware')
const botUserAgents = [
'googlebot',
'duckduckgo',
'Baiduspider',
'bingbot',
'Embedly',
'facebookexternalhit',
'LinkedInBot',
'outbrain',
'pinterest',
'quora link preview',
'rogerbot',
'showyoubot',
'Slackbot',
'TelegramBot',
'Twitterbot',
'vkShare',
'W3C_Validator',
'WhatsApp',
]
const app = express()
if (process.env.RENDERTRON_PROXY) {
app.use(rendertron.makeMiddleware({
proxyUrl: process.env.RENDERTRON_PROXY,
userAgentPattern: new RegExp(process.env.RENDERTRON_AGENTS_MATCHER || botUserAgents.join('|'), 'i'),
timeout: process.env.RENDERTRON_TIMEOUT || 5000,
}))
}
app.use(express.static(__dirname + '/dist', {
setHeaders: (res, path) => {
if (/.*\.min\..+\.js$/.test(path)) {
res.set('Cache-Control', 'public, max-age=31536000')
} else if (/min\/.+\.css$/.test(path)) {
res.set('Cache-Control', 'public, max-age=31536000')
} else if (/\.ttf$/.test(path)) {
res.set('Cache-Control', 'public, max-age=31536000')
} else if (/\.png$/.test(path)) {
res.set('Cache-Control', 'public, max-age=31536000')
}
}
}));
app.get('*', function (request, response) {
response.sendFile(path.resolve(__dirname + '/dist', 'index.html'))
});
app.listen(80)