From 34e54aef29210212344f8269dbfa1a34d8fc9ba1 Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Mon, 15 Apr 2024 15:15:13 -0400 Subject: [PATCH] refactor(pages,views,worker): disable runtime preload injection where possible --- src/pages/account.html | 7 ++++--- src/pages/account.js | 3 ++- src/views/home.js | 4 ++-- src/worker.js | 12 ++++++------ tsconfig.json | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 tsconfig.json diff --git a/src/pages/account.html b/src/pages/account.html index bdf8dc4..cf243b4 100644 --- a/src/pages/account.html +++ b/src/pages/account.html @@ -1,14 +1,13 @@ - - + + + diff --git a/src/pages/account.js b/src/pages/account.js index c9a2a33..eaae086 100644 --- a/src/pages/account.js +++ b/src/pages/account.js @@ -5,7 +5,8 @@ const sharedKeys = { window.addEventListener('DOMContentLoaded', e => { setTimeout(() => { - const key = !!globalThis.__args.env.DEV ? sharedKeys.test : sharedKeys.live + const url = new URL(globalThis.location.href) + const key = url.searchParams.get('dev') === 'true' ? sharedKeys.test : sharedKeys.live const stripe = Stripe(key) const elements = stripe.elements() diff --git a/src/views/home.js b/src/views/home.js index 4eaad3f..576c3dd 100644 --- a/src/views/home.js +++ b/src/views/home.js @@ -25,7 +25,7 @@ class ViewHome extends Tonic { webview_auto_register_service_workers: false, webview_service_worker_frame: false }, - path: 'pages/account.html', + path: `pages/account.html?dev=${process.env.DEV ? 'true' : 'false'}`, index: 14, closable: true, maximizable: false, @@ -173,7 +173,7 @@ class ViewHome extends Tonic { id="profile-public-key" > - + diff --git a/src/worker.js b/src/worker.js index b46e391..ec3d3d6 100644 --- a/src/worker.js +++ b/src/worker.js @@ -14,6 +14,11 @@ export default async function (req, env, ctx) { const p = path.join(navigatorPath, route.pathname.groups[0]) const params = url.searchParams + const headers = { + 'Content-Type': type || 'text/html', + 'Cache-Control': 'no-cache', + 'Access-Control-Allow-Origin': '*' + } let data = '' @@ -24,6 +29,7 @@ export default async function (req, env, ctx) { data = await res.text() } else if (!res.ok || res.status === 404) { data = '

Not Found

' + headers['Runtime-Preload-Injection'] = 'disabled' } } catch (err) { data = err.message @@ -98,11 +104,5 @@ export default async function (req, env, ctx) { const types = await lookup(path.extname(url.pathname).slice(1)) const type = types[0]?.mime ?? '' - const headers = { - 'Content-Type': type || 'text/html', - 'Cache-Control': 'no-cache', - 'Access-Control-Allow-Origin': '*' - } - return new Response(html, { status: 200, headers }) } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..cc1cae0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,32 @@ +{ + "include": [ + "src/*.js", + "src/**/*.js", + "src/**/**/*.js" + ], + "exclude": [ + "node_modules", + "types", + "build" + ], + "compilerOptions": { + "moduleResolution": "node", + "target": "es2022", + "module": "es2022", + "lib": ["es2022", "dom"], + "types": ["@socketsupply/socket"], + "removeComments": false, + "checkJs": true, + "allowJs": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, + "alwaysStrict": true, + "strictNullChecks": false, + "declaration": true, + "declarationMap": true, + "baseUrl": ".", + "paths": { + "npm:*": ["node_modules/*"] + } + } +}