Skip to content

fix(network): use curated node lists for CORS-compatible endpoints#3046

Merged
baktun14 merged 2 commits into
mainfrom
fix/net-cors-friendly-node-urls
Apr 9, 2026
Merged

fix(network): use curated node lists for CORS-compatible endpoints#3046
baktun14 merged 2 commits into
mainfrom
fix/net-cors-friendly-node-urls

Conversation

@baktun14

@baktun14 baktun14 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Why

Users are experiencing CORS errors in the browser when the console tries to reach REST API nodes. The root cause is that the generate script in packages/net pulls endpoint lists from meta.json, which includes many nodes that don't handle CORS preflight (OPTIONS) correctly — e.g. ecostake REST returns 501 on OPTIONS, which browsers reject even though it sends Access-Control-Allow-Origin: *.

The akash-network/net repo maintains curated api-nodes.txt and rpc-nodes.txt files with CORS-friendly nodes, but the generate script wasn't using them.

What

  • Updated the generate script to fetch api-nodes.txt and rpc-nodes.txt from the akash-network/net repo
  • These curated lists take priority over meta.json API lists when available
  • Falls back to meta.json if the txt files don't exist (e.g. sandbox/testnet)
  • Regenerated netConfigData.ts — mainnet REST goes from 12 endpoints (8 CORS-broken) to 4 (all CORS-verified), RPC from 9 to 6

Summary by CodeRabbit

  • Chores
    • Network loading now incorporates optional plain-text node lists, parses and merges them with metadata-derived API/RPC addresses, and de-duplicates entries while preferring parsed lists when present.
    • App version resolution now derives from the first available RPC URL, falling back to metadata or returning null when none exist; failures to fetch extra lists are non-fatal.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Script now fetches optional api-nodes.txt and rpc-nodes.txt (404 → null), parses and deduplicates URLs, merges them with metadata API/RPC lists, and derives the app version from the first computed RPC URL (fallback to metadata; null if none).

Changes

Cohort / File(s) Summary
Node-list fetching & merge logic
packages/net/scripts/generate.ts
Adds parallel fetching of api-nodes.txt and rpc-nodes.txt via fetchOptionalText (404 → null, other non-OK → throw). Introduces parseNodesTxt, normalizeUrl, and mergeUrls helpers to extract, normalize, and deduplicate http URLs. networkConfig.apiUrls / networkConfig.rpcUrls now prefer TXT-derived lists merged with meta.apis.rest / meta.apis.rpc; app version resolution uses rpcUrls[0] (fallback to first metaRpcUrls), returning null if no RPC URL exists.

Sequence Diagram(s)

sequenceDiagram
    participant Script as Script (generate.ts)
    participant Host as Remote Host
    participant RPC as RPC Endpoint

    Script->>Host: GET meta.json, faucet-url.txt, api-nodes.txt, rpc-nodes.txt
    Host-->>Script: meta.json, faucet-url.txt, api-nodes.txt, rpc-nodes.txt (404 allowed -> null)
    Script->>Script: parseNodesTxt(api-nodes.txt / rpc-nodes.txt)
    Script->>Script: mergeUrls(parsedTxt, meta.apis)
    alt rpcUrls available
        Script->>RPC: request app version via first rpcUrl
        RPC-->>Script: app version
    else no rpcUrls
        Script-->>Script: app version = null
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I fetched some nodes beneath the sun,

I trimmed and joined them one by one,
I de-duped links until they shone,
From RPC first the version’s won —
A happy hop: the build is done! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: using curated node lists instead of meta.json for CORS-compatible endpoints.
Description check ✅ Passed The description follows the template structure with clear 'Why' and 'What' sections explaining the problem, solution, and impact.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/net-cors-friendly-node-urls

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.84%. Comparing base (7da0013) to head (b269f5c).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3046      +/-   ##
==========================================
- Coverage   59.72%   58.84%   -0.89%     
==========================================
  Files        1035      995      -40     
  Lines       24304    23348     -956     
  Branches     6025     5874     -151     
==========================================
- Hits        14515    13738     -777     
+ Misses       8539     8372     -167     
+ Partials     1250     1238      -12     
Flag Coverage Δ *Carryforward flag
api 81.29% <ø> (+0.02%) ⬆️
deploy-web 43.26% <ø> (ø)
log-collector ?
notifications 86.06% <ø> (ø)
provider-console 81.48% <ø> (ø) Carriedforward from c63a02f
provider-proxy 85.21% <ø> (ø) Carriedforward from c63a02f
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.
see 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/net/scripts/generate.ts (1)

95-101: Harden TXT parsing to keep only valid HTTP(S) URLs.

At Line 95–101, startsWith("http") is too permissive and can pass malformed entries into generated config.

Suggested refactor
 function parseNodesTxt(content: string | null): string[] {
   if (!content) return [];
-  return content
+  return [...new Set(content
     .split("\n")
     .map(line => line.trim())
-    .filter(line => line.length > 0 && line.startsWith("http"));
+    .filter(line => {
+      if (!line) return false;
+      try {
+        const url = new URL(line);
+        return url.protocol === "http:" || url.protocol === "https:";
+      } catch {
+        return false;
+      }
+    }))];
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/net/scripts/generate.ts` around lines 95 - 101, The parseNodesTxt
function is too permissive using startsWith("http"); update parseNodesTxt to
only return properly formed HTTP/HTTPS URLs by parsing each trimmed line with a
URL validator (e.g., using the URL constructor or a strict regex), filtering out
lines that throw or whose protocol is not "http:" or "https:", and still
ignoring empty/comment lines; this ensures parseNodesTxt returns only valid
http(s) URLs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/net/scripts/generate.ts`:
- Around line 95-101: The parseNodesTxt function is too permissive using
startsWith("http"); update parseNodesTxt to only return properly formed
HTTP/HTTPS URLs by parsing each trimmed line with a URL validator (e.g., using
the URL constructor or a strict regex), filtering out lines that throw or whose
protocol is not "http:" or "https:", and still ignoring empty/comment lines;
this ensures parseNodesTxt returns only valid http(s) URLs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 134ba5e2-827d-4bab-a675-181159586a1a

📥 Commits

Reviewing files that changed from the base of the PR and between 7da0013 and 1ea29cd.

⛔ Files ignored due to path filters (1)
  • packages/net/src/generated/netConfigData.ts is excluded by !**/generated/**
📒 Files selected for processing (1)
  • packages/net/scripts/generate.ts

Comment thread packages/net/scripts/generate.ts Outdated
The generate script now fetches api-nodes.txt and rpc-nodes.txt from
the akash-network/net repo and merges them with meta.json entries.
Curated txt file nodes are placed first (CORS-friendly, prioritized),
followed by remaining meta.json nodes deduplicated by normalized URL.
Falls back to meta.json only when txt files are unavailable.
@baktun14
baktun14 force-pushed the fix/net-cors-friendly-node-urls branch from 1ea29cd to c63a02f Compare April 8, 2026 01:17
Only return null on 404 (file doesn't exist), throw on other errors
to avoid silently falling back to meta.json during transient failures.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/net/scripts/generate.ts (1)

113-117: Consider defensive error handling for malformed URLs.

new URL(url) throws a TypeError if the input is malformed. Since the URLs originate from external txt files, a malformed entry (e.g., "http:// invalid") would crash the entire generate script. While these files are curated, adding a try/catch or validating URLs in parseNodesTxt would make the script more resilient and provide clearer error messages.

💡 Optional: wrap in try/catch to skip invalid URLs
 function normalizeUrl(url: string): string {
+  try {
     const parsed = new URL(url);
     const defaultPort = parsed.protocol === "https:" ? "443" : "80";
     return `${parsed.protocol}//${parsed.hostname}:${parsed.port || defaultPort}${parsed.pathname.replace(/\/$/, "")}`;
+  } catch {
+    console.warn(`Skipping malformed URL: ${url}`);
+    return url; // return as-is to allow downstream deduplication
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/net/scripts/generate.ts` around lines 113 - 117, The normalizeUrl
function calls new URL(url) which can throw for malformed inputs; wrap the
parsing in a try/catch (or validate earlier in parseNodesTxt) so the generate
script doesn't crash on a bad entry: inside normalizeUrl (or in parseNodesTxt
before calling it) catch URL parsing errors, log a clear warning including the
offending string and skip/return a safe fallback (e.g., null or throw a custom
error handled by the caller) so callers like parseNodesTxt can filter out
invalid entries instead of letting a TypeError bubble up.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/net/scripts/generate.ts`:
- Around line 113-117: The normalizeUrl function calls new URL(url) which can
throw for malformed inputs; wrap the parsing in a try/catch (or validate earlier
in parseNodesTxt) so the generate script doesn't crash on a bad entry: inside
normalizeUrl (or in parseNodesTxt before calling it) catch URL parsing errors,
log a clear warning including the offending string and skip/return a safe
fallback (e.g., null or throw a custom error handled by the caller) so callers
like parseNodesTxt can filter out invalid entries instead of letting a TypeError
bubble up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ce59281-0faf-4531-94ab-544dbd84ab61

📥 Commits

Reviewing files that changed from the base of the PR and between c63a02f and b269f5c.

📒 Files selected for processing (1)
  • packages/net/scripts/generate.ts

@baktun14
baktun14 added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit 9ccf71a Apr 9, 2026
56 checks passed
@baktun14
baktun14 deleted the fix/net-cors-friendly-node-urls branch April 9, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants