-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from arcana-network/testnet
Gasless release
- Loading branch information
Showing
105 changed files
with
56,271 additions
and
23,558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ pnpm-debug.log* | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# Local Netlify folder | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
|
||
// eslint-disable-next-line import/exports-last | ||
export default async (req, context) => { | ||
const res = await context.next() | ||
|
||
try { | ||
const appId = getAppId(req.url) | ||
|
||
let header = getHeader('') | ||
|
||
if (!appId) { | ||
throw new Error('Invalid AppId') | ||
} | ||
|
||
if (!(appId == 'assets' || appId == 'global-redirect')) { | ||
const domain = await fetchDomain(appId) | ||
header = getHeader(domain) | ||
} | ||
res.headers.set('Content-Security-Policy', header) | ||
|
||
return res | ||
} catch (e) { | ||
console.log({ e }) | ||
|
||
const response = JSON.stringify({ message: 'Not allowed' }) | ||
|
||
return new Response(response, { status: 403 }) | ||
} | ||
} | ||
|
||
const PATTERN = new URLPattern({ | ||
pathname: '/:appId/*', | ||
}) | ||
|
||
const getAppId = (path) => { | ||
const r = PATTERN.exec(path) | ||
|
||
if (r) { | ||
return r.pathname.groups.appId | ||
} | ||
|
||
return null | ||
} | ||
|
||
const fetchDomain = async (appId) => { | ||
const gatewayUrl = Netlify.env.get('VUE_APP_WALLET_GATEWAY') | ||
|
||
const url = new URL('/api/v1/get-app-config/', gatewayUrl) | ||
|
||
url.searchParams.set('id', appId) | ||
|
||
const res = await fetch(url.href) | ||
|
||
if (res.status < 400) { | ||
const data = await res.json() | ||
return data.wallet_domain | ||
} else { | ||
throw new Error('Invalid AppId') | ||
} | ||
} | ||
|
||
const getHeader = (domain = '') => | ||
"font-src 'self' https://*.cloudfront.net data:;" + | ||
"img-src 'self' data: https:;" + | ||
"script-src 'self' 'unsafe-inline' https://*.cloudfront.net *.google-analytics.com *.googletagmanager.com;" + | ||
"style-src 'self' 'unsafe-inline' https://*.cloudfront.net;" + | ||
'frame-src *.arcana.network *.transak.com *.ramp.network;' + | ||
(domain.length > 0 | ||
? `frame-ancestors ${Netlify.env.get( | ||
'VUE_APP_WALLET_AUTH_URL' | ||
)} *.arcana.network http://localhost http://localhost:* ${domain};` | ||
: '') |
Oops, something went wrong.