Skip to content

Commit

Permalink
fix: preflight cors + caching + new route (#68)
Browse files Browse the repository at this point in the history
* fix preflight cors

* fix: add new route
  • Loading branch information
fforbeck authored Jan 13, 2025
1 parent 702dc76 commit 0e18daa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/edge-gateway-link/src/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ export function addCorsHeaders (request, response) {
*/
export function corsPreflightRequest (request) {
const headers = new Headers()
headers.set('Access-Control-Allow-Origin', request.headers.get('origin') || '*')

const origin = request.headers.get('origin')
if (origin) {
headers.set('Access-Control-Allow-Origin', origin)
headers.set('Vary', 'Origin')
} else {
headers.set('Access-Control-Allow-Origin', '*')
}

headers.set('Access-Control-Allow-Methods', 'GET, HEAD, POST, OPTIONS')
headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization')
headers.set('Access-Control-Max-Age', '86400') // Cache preflight for 24 hours

return new Response(null, { headers, status: 204 })
}
2 changes: 2 additions & 0 deletions packages/edge-gateway-link/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ENV = "dev"
# name = "w3link-edge-gateway-production"
account_id = "fffa4b4363a7e5250af8357087263b3a" # Protocol Labs CF account
routes = [
{ pattern = "w3s.link/", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "w3s.link/ipfs/*", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "*.ipfs.w3s.link/*", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "ipfs.w3s.link/*", zone_id = "ae60d8f737317467ec666dc3851a6277" },
Expand Down Expand Up @@ -50,6 +51,7 @@ environment = "production"
# name = "gateway-nft-storage-staging"
account_id = "fffa4b4363a7e5250af8357087263b3a" # Protocol Labs CF account
routes = [
{ pattern = "w3s-staging.link/", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "*.ipfs-staging.w3s.link/*", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "ipfs-staging.w3s.link/*", zone_id = "ae60d8f737317467ec666dc3851a6277" },
{ pattern = "*.ipfs-staging.w3s.link", zone_id = "ae60d8f737317467ec666dc3851a6277" },
Expand Down

0 comments on commit 0e18daa

Please sign in to comment.