Skip to content

Commit 0affcca

Browse files
authored
Merge pull request #30 from Johnaverse/copilot/sub-pr-29
Harden CSP, bundle UI assets locally, add Node engines constraint, optimize countChainsByTag, add unit tests
2 parents 75291cb + 1c9c728 commit 0affcca

14 files changed

Lines changed: 152 additions & 23 deletions

dataService.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,10 +1039,22 @@ export function getAllChains() {
10391039
*/
10401040
export function countChainsByTag(chains) {
10411041
const totalChains = chains.length;
1042-
const totalTestnets = chains.filter(c => c.tags?.includes('Testnet')).length;
1043-
const totalL2s = chains.filter(c => c.tags?.includes('L2')).length;
1044-
const totalBeacons = chains.filter(c => c.tags?.includes('Beacon')).length;
1045-
const totalMainnets = chains.filter(c => !c.tags?.includes('Testnet') && !c.tags?.includes('L2') && !c.tags?.includes('Beacon')).length;
1042+
let totalTestnets = 0;
1043+
let totalL2s = 0;
1044+
let totalBeacons = 0;
1045+
let totalMainnets = 0;
1046+
1047+
for (const chain of chains) {
1048+
const tags = chain.tags || [];
1049+
const isTestnet = tags.includes('Testnet');
1050+
const isL2 = tags.includes('L2');
1051+
const isBeacon = tags.includes('Beacon');
1052+
1053+
if (isTestnet) totalTestnets += 1;
1054+
if (isL2) totalL2s += 1;
1055+
if (isBeacon) totalBeacons += 1;
1056+
if (!isTestnet && !isL2 && !isBeacon) totalMainnets += 1;
1057+
}
10461058

10471059
return { totalChains, totalMainnets, totalTestnets, totalL2s, totalBeacons };
10481060
}

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export async function buildApp(options = {}) {
5252
contentSecurityPolicy: {
5353
directives: {
5454
defaultSrc: ["'self'"],
55-
scriptSrc: ["'self'", "https://unpkg.com"],
56-
styleSrc: ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
57-
fontSrc: ["'self'", "https://fonts.gstatic.com"],
58-
connectSrc: ["'self'", "https://raw.githubusercontent.com"],
55+
scriptSrc: ["'self'"],
56+
styleSrc: ["'self'"],
57+
fontSrc: ["'self'"],
58+
connectSrc: ["'self'"],
5959
imgSrc: ["'self'", "data:"]
6060
}
6161
}

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"url": "https://github.com/Johnaverse/chains-api/issues"
2929
},
3030
"homepage": "https://github.com/Johnaverse/chains-api#readme",
31+
"engines": {
32+
"node": ">=20"
33+
},
3134
"dependencies": {
3235
"@fastify/cors": "^11.2.0",
3336
"@fastify/helmet": "^13.0.2",

public/3d-force-graph.min.js

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

public/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ function initUI() {
233233

234234
async function fetchData() {
235235
try {
236-
// Try local API first (/export), fall back to GitHub raw
236+
// Try local API first (/export), fall back to bundled export.json
237237
let res;
238238
try {
239239
res = await fetch('/export');
240240
if (!res.ok) throw new Error('Local export unavailable');
241241
} catch {
242-
res = await fetch('https://raw.githubusercontent.com/Johnaverse/chains-api/refs/heads/main/public/export.json');
242+
res = await fetch('export.json');
243243
}
244244
const exportData = await res.json();
245245

public/fonts/inter-300.ttf

318 KB
Binary file not shown.

public/fonts/inter-400.ttf

317 KB
Binary file not shown.

public/fonts/inter-500.ttf

318 KB
Binary file not shown.

public/fonts/inter-600.ttf

318 KB
Binary file not shown.

0 commit comments

Comments
 (0)