Skip to content

Commit 0a6e4e3

Browse files
chore: fix prod build
1 parent 104d08e commit 0a6e4e3

File tree

9 files changed

+139
-30
lines changed

9 files changed

+139
-30
lines changed

.gitignore

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
\.cache
2-
.dep
3-
.local
4-
data
5-
viewer
6-
figs
7-
log
8-
docs/build
9-
docs/repo
10-
notes/
11-
vendor
12-
pangraph
13-
pangraph.tar.gz
14-
bin
15-
tutorial
16-
playgrounds
17-
.vscode
18-
script/synthetic_data
19-
script/panx_data
20-
script/.snakemake
21-
script/projections
22-
script/size-benchmark
23-
script/incremental_size
24-
script/panx_results
25-
script/local_scripts
2+
/\.dep
3+
/\.local
4+
/data
5+
/viewer
6+
/figs
7+
/log
8+
/docs/build
9+
/docs/repo
10+
/notes/
11+
/vendor
12+
/pangraph
13+
/pangraph.tar.gz
14+
/bin
15+
/tutorial
16+
/playgrounds
17+
/\.vscode
18+
/script/synthetic_data
19+
/script/panx_data
20+
/script/.snakemake
21+
/script/projections
22+
/script/size-benchmark
23+
/script/incremental_size
24+
/script/panx_results
25+
/script/local_scripts
2626
__pycache__
27-
tests/data
27+
/tests/data
2828

29-
deps/minimap2/build
30-
deps/minimap2/products
29+
/deps/minimap2/build
30+
/deps/minimap2/products
3131

3232
*.aux
3333
*.bbl
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable prefer-destructuring,sonarjs/no-collapsible-if,unicorn/no-lonely-if */
2+
// Implements rewrite of non-compressed to .gz URLs using AWS
3+
// Lambda@Edge. This is useful if you have precompressed your files.
4+
//
5+
// Usage:
6+
// Create an AWS Lambda function and attach it to "Origin Request" event of a
7+
// Cloudfront distribution
8+
9+
const ARCHIVE_EXTS = ['.7z', '.br', '.bz2', '.gz', '.lzma', '.xz', '.zip', '.zst']
10+
11+
function getHeader(headers, headerName) {
12+
const header = headers[headerName.toLowerCase()]
13+
if (!header || !header[0] || !header[0].value) {
14+
return undefined
15+
}
16+
return header[0].value
17+
}
18+
19+
function acceptsEncoding(headers, encoding) {
20+
const ae = getHeader(headers, 'Accept-Encoding')
21+
if (!ae || typeof ae != 'string') {
22+
return false
23+
}
24+
return ae.split(',').some((e) => e.trim().toLowerCase().startsWith(encoding.toLowerCase()))
25+
}
26+
27+
function handler(event, context, callback) {
28+
const request = event.Records[0].cf.request
29+
const headers = request.headers
30+
31+
// If not an archive file (which are not precompressed), rewrite the URL to
32+
// get the corresponding .gz file
33+
if (ARCHIVE_EXTS.every((ext) => !request.uri.endsWith(ext))) {
34+
if (acceptsEncoding(headers, 'gzip')) {
35+
request.uri += '.gz'
36+
}
37+
}
38+
39+
callback(null, request)
40+
}
41+
42+
exports.handler = handler
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Adds additional headers to the response, including security headers and CORS.
2+
// Suited for serving data and APIs.
3+
//
4+
// See also:
5+
// - https://securityheaders.com/
6+
//
7+
// Usage: Create an AWS Lambda@Edge function and attach it to "Viewer Response"
8+
// event of a Cloudfront distribution
9+
10+
const NEW_HEADERS = {
11+
'Access-Control-Allow-Origin': '*',
12+
'Access-Control-Allow-Methods': 'GET, OPTIONS',
13+
'Content-Security-Policy': `default-src 'none'; frame-ancestors 'none'`,
14+
'Strict-Transport-Security': 'max-age=15768000; includeSubDomains; preload',
15+
'X-Content-Type-Options': 'nosniff',
16+
'X-DNS-Prefetch-Control': 'off',
17+
'X-Download-Options': 'noopen',
18+
'X-Frame-Options': 'DENY',
19+
'X-XSS-Protection': '1; mode=block',
20+
}
21+
22+
function addHeaders(headersObject) {
23+
return Object.fromEntries(
24+
Object.entries(headersObject).map(([header, value]) => [header.toLowerCase(), [{ key: header, value }]]),
25+
)
26+
}
27+
28+
const HEADERS_TO_REMOVE = new Set(['server', 'via'])
29+
30+
function filterHeaders(headers) {
31+
return Object.entries(headers).reduce((result, [key, value]) => {
32+
if (HEADERS_TO_REMOVE.has(key.toLowerCase())) {
33+
return result
34+
}
35+
36+
if (key.toLowerCase().includes('powered-by')) {
37+
return result
38+
}
39+
40+
return { ...result, [key.toLowerCase()]: value }
41+
}, {})
42+
}
43+
44+
function modifyHeaders({ response }) {
45+
let newHeaders = addHeaders(NEW_HEADERS)
46+
47+
newHeaders = {
48+
...response.headers,
49+
...newHeaders,
50+
}
51+
52+
newHeaders = filterHeaders(newHeaders)
53+
54+
return newHeaders
55+
}
56+
57+
exports.handler = (event, context, callback) => {
58+
const { request, response } = event.Records[0].cf
59+
response.headers = modifyHeaders({ request, response })
60+
callback(null, response)
61+
}
62+
63+
exports.modifyHeaders = modifyHeaders
File renamed without changes.

web/infra/web/lambda-at-edge/ViewerResponse.lambda.js renamed to web/infra/web/lambda-at-edge/ViewerResponse.lambda.cjs

File renamed without changes.

web/src/pages/_error.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { ErrorPage } from 'src/components/Error/ErrorPage'
1+
import { ErrorPage } from 'src/components/Error/ErrorPage'
2+
3+
// eslint-disable-next-line unicorn/prefer-export-from
4+
export default ErrorPage

web/tools/server/dataServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import allowMethods from 'allow-methods'
1818
import compression from 'compression'
1919
import morgan from 'morgan'
2020
import expressStaticGzip from 'express-static-gzip'
21-
import { modifyHeaders } from '../../infra/data/lambda-at-edge/ViewerResponse.lambda'
21+
import { modifyHeaders } from '../../infra/data/lambda-at-edge/ViewerResponse.lambda.cjs'
2222

2323
export interface NewHeaders {
2424
[key: string]: { key: string; value: string }[]

web/tools/server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import morgan from 'morgan'
1919
import expressStaticGzip from 'express-static-gzip'
2020
import { getenv } from '../../lib/getenv'
2121
import { findModuleRoot } from '../../lib/findModuleRoot'
22-
import { modifyHeaders } from '../../infra/web/lambda-at-edge/ViewerResponse.lambda'
22+
import { modifyHeaders } from '../../infra/web/lambda-at-edge/ViewerResponse.lambda.cjs'
2323

2424
const { moduleRoot } = findModuleRoot()
2525

web/tsconfig.ts-node.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"allowJs": true,
1818
"skipLibCheck": true,
1919
"strict": false,
20+
"allowSyntheticDefaultImports": true,
2021
"forceConsistentCasingInFileNames": true,
2122
"noEmit": true,
2223
"incremental": true,

0 commit comments

Comments
 (0)