-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathserve-prod.js
More file actions
44 lines (41 loc) · 1.14 KB
/
serve-prod.js
File metadata and controls
44 lines (41 loc) · 1.14 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
36
37
38
39
40
41
42
43
44
// @ts-check
const path = require('path')
const http = require('http')
const serveHandler = require('serve-handler')
const { getCsp, getPermissionsPolicy } = require('../internals/getSecurityHeaders.js')
const csp = getCsp({ isDev: false, isExtension: false })
const permissionsPolicy = getPermissionsPolicy()
console.log(`Content-Security-Policy: ${csp}\n`)
console.log(`Permissions-Policy: ${permissionsPolicy}\n`)
const root = path.resolve(__dirname, '..')
const server = http.createServer((request, response) => {
return serveHandler(request, response, {
public: path.join(root, 'build'),
rewrites: [
{
source: '**',
destination: '/index.html',
},
],
// Disable etag so we don't need to clear cache if we only change CSP.
etag: false,
headers: [
{
source: '**',
headers: [
{
key: 'Content-Security-Policy',
value: csp,
},
{
key: 'Permissions-Policy',
value: permissionsPolicy,
},
],
},
],
})
})
server.listen(5000, () => {
console.log('Running at http://localhost:5000')
})