Skip to content

refactor(api): centralize network and contract config for API handlers - #77

Merged
MEECHAIN1 merged 3 commits into
mainfrom
codex/check-for-duplicate-api-function-sets-0e0j33
Jun 18, 2026
Merged

MEECHAIN1 merged 3 commits into
mainfrom
codex/check-for-duplicate-api-function-sets-0e0j33

Conversation

@MEECHAIN1

Copy link
Copy Markdown
Owner

Motivation

  • Multiple API handlers repeated the same chain/RPC/contract resolution logic which can drift and produce inconsistent endpoint responses.
  • Centralizing resolution reduces duplication and makes it easier to keep all endpoints in sync.

Description

  • Added functions/api/_shared.mjs as a single source of truth exporting DEFAULT_CHAIN_ID, DEFAULT_RPC_URL, DEFAULT_CONTRACTS, and resolver functions resolveChainId, resolveRpcUrl, and resolveContracts.
  • Updated functions/api/health.js to import the shared resolvers and use resolveChainId, resolveRpcUrl, and resolveContracts, while preserving contracts.staking for backward compatibility.
  • Updated functions/api/network.js to use resolveChainId, resolveRpcUrl, and resolveContracts instead of in-file hard-coded/duplicated values.
  • Updated functions/api/web3/status.js to use the shared resolvers for rpc, chainId, and contracts so reported values match other endpoints.

Testing

  • Ran node --check functions/api/_shared.mjs and node --check on the updated handlers which completed successfully.
  • Attempted npm test -- --grep "api" but the test runner could not execute in this environment because mocha is not installed, so the full test suite did not run.

Codex Task

@vercel

vercel Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
connect.meechain Error Error May 4, 2026 4:14pm
mee-chain-connect Error Error May 4, 2026 4:14pm
meebot Error Error May 4, 2026 4:14pm
meechain Error Error May 4, 2026 4:14pm
meechain-connect Error Error May 4, 2026 4:14pm

Request Review

@coderabbitai

coderabbitai Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@MEECHAIN1, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 42 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b38ab056-225d-4f74-bb70-ac937a528aca

📥 Commits

Reviewing files that changed from the base of the PR and between 7a5f5b3 and 170ae1e.

📒 Files selected for processing (4)
  • functions/api/_shared.mjs
  • functions/api/health.js
  • functions/api/network.js
  • functions/api/web3/status.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/check-for-duplicate-api-function-sets-0e0j33

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@railway-app

railway-app Bot commented May 4, 2026

Copy link
Copy Markdown

🚅 Deployed to the MeeChain-Connect-pr-77 environment in meechain

5 services not affected by this PR
  • Redis-wHAO
  • Postgres-X79I
  • Postgres
  • MeeChain
  • Redis

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c547918e29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread functions/api/_shared.mjs
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
meechain-connect c547918 May 04 2026, 04:15 PM

Comment thread functions/api/health.js Outdated
MEECHAIN1 and others added 2 commits June 18, 2026 19:45
…0e0j33

Signed-off-by: ธณวัฒน์ ประวันตา <pouaun2499@gmail.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Signed-off-by: ธณวัฒน์ ประวันตา <pouaun2499@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 170ae1e988

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread functions/api/health.js
Comment on lines +21 to +24
contracts: {
token: contracts.token,
nft: contracts.nft,
staking: contracts.portal,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Close the health contracts object

The added contracts block is never closed before the old chainId/rpc fields continue, so the ES-module parser reaches the final }; while the outer data object is still open. Any deployment that loads /api/health will fail with a syntax error instead of returning the health JSON; close this block or remove the stale config fields.

Useful? React with 👍 / 👎.

Comment on lines +7 to +12
export async function onRequestGet(ctx) {
const { env } = ctx;

const rpcUrl = resolveRpcUrl(env);
const chainId = resolveChainId(env);
const contracts = resolveContracts(env);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the nested duplicate status handler

The newly inserted onRequestGet starts here but is not closed before the existing import and handler below it, which makes the file invalid as an ES module because the later import is parsed inside a function body. In any Cloudflare Pages deployment that loads /api/web3/status, the route will fail to load; fold these resolver variables into the existing handler or remove this duplicate wrapper.

Useful? React with 👍 / 👎.

@MEECHAIN1
MEECHAIN1 merged commit 3a211d2 into main Jun 18, 2026
2 of 9 checks passed
@MEECHAIN1
MEECHAIN1 deleted the codex/check-for-duplicate-api-function-sets-0e0j33 branch June 18, 2026 12:48
@railway-app
railway-app Bot temporarily deployed to meechain / MeeChain-Connect-pr-77-2a609674-c0da-47f1-ac25-fe34310569ed June 18, 2026 12:49 Destroyed

This branch had an error being deployed

5 failed (outdated) deployments
meechain / MeeChain-Connect-pr-77-2a609674-c0da-47f1-ac25-fe34310569ed — 170ae1e9 Deployed Jun 18, 2026 by railway-app[bot]
Preview – meebot — c547918e Deployed May 4, 2026 by vercel[bot]
Preview – connect.meechain — c547918e Deployed May 4, 2026 by vercel[bot]
Preview – mee-chain-connect — c547918e Deployed May 4, 2026 by vercel[bot]
Preview – meechain — c547918e Deployed May 4, 2026 by vercel[bot]
Preview – meechain-connect — c547918e Deployed May 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant