Skip to content

Conversation

@Gaubee
Copy link
Contributor

@Gaubee Gaubee commented Jan 21, 2026

Problem

Remote miniapp (rwa-hub) requests are being rewritten incorrectly:

Before (wrong):

Request: /assets/main.js
Rewritten: https://bioforestchain.github.io/KeyApp/webapp/miniapps/rwa-hub/KeyApp/webapp/miniapps/rwa-hub/assets/main.js

After (correct):

Request: /assets/main.js
Rewritten: https://bioforestchain.github.io/KeyApp/webapp/miniapps/rwa-hub/assets/main.js

Root Cause

The old code used string concatenation which duplicated the path:

const rewrittenUrl = `${origin}${parsedReqUrl.pathname}...`;
// origin = https://bioforestchain.github.io/KeyApp/webapp/miniapps/rwa-hub
// pathname = /KeyApp/webapp/miniapps/rwa-hub/assets/main.js
// Result: path duplicated!

Fix

Use placeholder origin approach to properly normalize the URL:

const normalized = new URL(
  parsedReqUrl.pathname + parsedReqUrl.search + parsedReqUrl.hash,
  PLACEHOLDER_ORIGIN + '/',
);
const rewrittenUrl = normalized.href.replace(PLACEHOLDER_ORIGIN + '/', targetBase);

This ensures the pathname is correctly resolved relative to the target base URL.

@Gaubee Gaubee merged commit 7dcfc2a into main Jan 21, 2026
5 checks passed
@Gaubee Gaubee deleted the fix/wujie-url-rewrite branch January 21, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants