Skip to content

Commit 9180677

Browse files
Pigbibiclaude
andcommitted
feat: extract JS+CSS to external files, tighten CSP, remove hardcoding
- Extract 142KB JS to /app.js (1h cache, 'script-src self' now clean) - Extract 29KB CSS to /app.css (1h cache, 'style-src self' now clean) - index.html shrinks from 179KB to 16KB - Remove DEFAULT_VARIABLE_SCOPE hardcoding (import from config.js) - Worker serves /app.css and /app.js with cache headers - CSP: removed all 'unsafe-inline' directives Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0086e23 commit 9180677

8 files changed

Lines changed: 4661 additions & 4379 deletions

File tree

web/strategy-switch-console/app.css

Lines changed: 1309 additions & 0 deletions
Large diffs are not rendered by default.

web/strategy-switch-console/app.js

Lines changed: 3054 additions & 0 deletions
Large diffs are not rendered by default.

web/strategy-switch-console/app_css.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/app_js.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/index.html

Lines changed: 3 additions & 4365 deletions
Large diffs are not rendered by default.

web/strategy-switch-console/page_asset.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/strategy_profiles_asset.js

Lines changed: 283 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/worker.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PAGE_HTML } from "./page_asset.js";
33
import { DEFAULT_STRATEGY_PROFILES } from "./strategy_profiles_asset.js";
44
import {
55
DCA_SUPPORTED_PLATFORMS,
6-
DEFAULT_VARIABLE_SCOPES,
6+
DEFAULT_VARIABLE_SCOPES as DEFAULT_VARIABLE_SCOPE,
77
PLATFORM_REPOSITORIES,
88
DOMAIN_LABELS,
99
PLATFORM_MIN_RESERVED_CASH_VARIABLES,
@@ -15,6 +15,8 @@ import {
1515
DCA_PROFILE_DEFAULTS,
1616
STRATEGY_FEATURES,
1717
} from "./config.js";
18+
import { APP_CSS } from "./app_css.js";
19+
import { APP_JS } from "./app_js.js";
1820

1921
const DEFAULT_REPOSITORY = "QuantStrategyLab/QuantRuntimeSettings";
2022
const DEFAULT_WORKFLOW = "manual-strategy-switch.yml";
@@ -50,14 +52,6 @@ const PLATFORM_REPOSITORY_ENV = {
5052
qmt: ["STRATEGY_SWITCH_QMT_REPO", "RUNTIME_SETTINGS_QMT_REPO"],
5153
binance: ["STRATEGY_SWITCH_BINANCE_REPO", "RUNTIME_SETTINGS_BINANCE_REPO"],
5254
};
53-
const DEFAULT_VARIABLE_SCOPE = {
54-
longbridge: "environment",
55-
ibkr: "repository",
56-
schwab: "repository",
57-
firstrade: "repository",
58-
qmt: "repository",
59-
binance: "repository",
60-
};
6155
const PLATFORM_CASH_ONLY_EXECUTION_VARIABLES = {
6256
longbridge: "LONGBRIDGE_CASH_ONLY_EXECUTION",
6357
ibkr: "IBKR_CASH_ONLY_EXECUTION",
@@ -120,7 +114,7 @@ const SECURITY_HEADERS = {
120114
"form-action 'self'",
121115
"img-src 'self' data:",
122116
"connect-src 'self'",
123-
"script-src 'self' 'unsafe-inline'",
117+
"script-src 'self'",
124118
"style-src 'self'",
125119
].join("; "),
126120
"Permissions-Policy": "camera=(), microphone=(), geolocation=(), payment=(), usb=()",
@@ -153,6 +147,8 @@ export default {
153147
}
154148
if (url.pathname === "/api/logout" && request.method === "POST") return logout(request);
155149
if (url.pathname === "/api/switch" && request.method === "POST") return await dispatchSwitch(request, env);
150+
if (url.pathname === "/app.css") return new Response(APP_CSS, { status: 200, headers: { "Content-Type": "text/css; charset=utf-8", "Cache-Control": "public, max-age=3600" } });
151+
if (url.pathname === "/app.js") return new Response(APP_JS, { status: 200, headers: { "Content-Type": "application/javascript; charset=utf-8", "Cache-Control": "public, max-age=3600" } });
156152
return html(PAGE_HTML);
157153
} catch (error) {
158154
return json({ ok: false, error: error.message || "unexpected error" }, error.status || 500);

0 commit comments

Comments
 (0)