Skip to content

Commit 2037c49

Browse files
committed
fix: test config with _headers and _redirects file
1 parent 24e5e8a commit 2037c49

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

.github/workflows/deploy.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ jobs:
1818
env: ${{ steps.set-env.outputs.env }}
1919
steps:
2020
- id: set-env
21-
run: |
22-
if [ "${{ github.ref_name }}" == "master" ] || [ "${{ github.ref_name }}" == "fix-cloudflare-deployment-scripts-update" ]; then
21+
run: |
22+
if [ "${{ github.ref_name }}" == "dev" ]; then
2323
export ENV=production
2424
fi
25-
26-
if [ "${{ github.ref_name }}" == "dev" ]; then
25+
if [ "${{ github.ref_name }}" == "dev" ] || [ "${{ github.ref_name }}" == "fix-cloudflare-deployment-scripts-update" ]; then
2726
export ENV=staging
2827
fi
2928

functions/_middleware.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export async function onRequest(context) {
2+
if (context.request.method === 'OPTIONS') {
3+
return new Response(null, {
4+
status: 204,
5+
headers: {
6+
'Access-Control-Allow-Origin': '*',
7+
'Access-Control-Allow-Methods': 'GET, HEAD, POST, OPTIONS',
8+
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
9+
},
10+
});
11+
}
12+
13+
// Let static assets handle all other requests
14+
return context.next();
15+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "mocha 'tests/tokenAddition'",
88
"test-all": "mocha 'tests'",
9-
"build": "rimraf build && mkdir -p build/tokenlists && node src/write.js",
9+
"build": "rimraf build && mkdir -p build/tokenlists build/functions && node src/write.js && cp src/_headers build/_headers && cp src/_redirects build/_redirects && cp functions/_middleware.js build/functions/_middleware.js",
1010
"lint": "eslint \"./src/*\"",
1111
"lint:fix": "eslint --fix \"./src/*\"",
1212
"lint-tests:fix": "eslint --fix \"./tests/*\""

src/_headers

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Access-Control-Allow-Origin: *
3+
Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS
4+
Access-Control-Allow-Headers: Content-Type, X-Requested-With

src/_redirects

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Redirect root to listRegistry.json
2+
/ /listRegistry.json 200
3+
4+
# Serve listRegistry.json for explicit requests
5+
/listRegistry.json /listRegistry.json 200
6+
7+
# Serve token lists from tokenlists directory
8+
/tokenlists/* /tokenlists/:splat 200

0 commit comments

Comments
 (0)