forked from feature-hub/feature-hub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-simple.config.js
84 lines (72 loc) · 2.34 KB
/
aws-simple.config.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// @ts-check
const globby = require('globby');
const path = require('path');
const basename = 'packages/website/build/feature-hub';
const indexFilenames = new Set();
const binaryDirnames = new Set();
const nonBinaryDirnames = new Set();
const filenames = globby
.sync(path.join(__dirname, 'packages/website/build/feature-hub/**/*'))
.map((filename) => path.relative(__dirname, filename));
for (const filename of filenames) {
if (path.basename(filename) === 'index.html') {
indexFilenames.add(filename);
} else if (path.extname(filename) === '.png') {
binaryDirnames.add(path.dirname(filename));
} else {
nonBinaryDirnames.add(path.dirname(filename));
}
}
const responseHeaders = {
'Cache-Control': `public, max-age=${60 * 5}`,
'Strict-Transport-Security': `max-age=${
60 * 60 * 24 * 365
}; includeSubDomains`,
'X-Frame-Options': 'SAMEORIGIN',
'X-XSS-Protection': '1; mode=block',
'X-Content-Type-Options': 'nosniff',
'Content-Security-Policy':
"default-src 'self' 'unsafe-eval' 'unsafe-inline' unpkg.com cdnjs.cloudflare.com cdn.jsdelivr.net; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com cdnjs.cloudflare.com cdn.jsdelivr.net; img-src 'self' img.shields.io data:; connect-src 'self' *.algolia.net; upgrade-insecure-requests; block-all-mixed-content;",
};
/** @type {Record<string, import('aws-simple').Route>} */
const routes = {};
for (const filename of indexFilenames) {
routes['/' + path.relative(basename, path.dirname(filename))] = {
kind: 'file',
filename,
responseHeaders,
};
}
for (const dirname of binaryDirnames) {
routes['/' + path.relative(basename, dirname) + '/'] = {
kind: 'folder',
dirname,
responseHeaders,
binaryMediaTypes: ['image/png'],
};
}
for (const dirname of nonBinaryDirnames) {
if (dirname === basename) {
continue;
}
routes['/' + path.relative(basename, dirname) + '/'] = {
kind: 'folder',
dirname,
responseHeaders,
};
}
const aliasRecordName = process.env.AWS_ALIAS_RECORD_NAME || undefined;
/**
* @type {import('aws-simple').App}
*/
exports.default = {
appName: 'featurehub',
appVersion: aliasRecordName,
customDomain: {
certificateArn: process.env.AWS_CERTIFICATE_ARN,
hostedZoneId: process.env.AWS_HOSTED_ZONE_ID,
hostedZoneName: process.env.AWS_HOSTED_ZONE_NAME,
aliasRecordName,
},
routes: () => routes,
};