Skip to content

Commit

Permalink
fix(http): change proxy url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Mar 20, 2024
1 parent 3c9feb4 commit 30a32f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
11 changes: 4 additions & 7 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ var nativeBridge = (function (exports) {
const proxyUrl = new URL(url);
const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
const isHttps = proxyUrl.protocol === 'https:';
const originalHost = encodeURIComponent(proxyUrl.host);
const originalPathname = proxyUrl.pathname;
proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.hostname = bridgeUrl.hostname;
proxyUrl.port = bridgeUrl.port;
proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`;
return proxyUrl.toString();
bridgeUrl.search = proxyUrl.search;
bridgeUrl.hash = proxyUrl.hash;
bridgeUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`;
return bridgeUrl.toString();
};
const initBridge = (w) => {
const getPlatformId = (win) => {
Expand Down
13 changes: 5 additions & 8 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,12 @@ const createProxyUrl = (url: string, win: WindowCapacitor): string => {
const proxyUrl = new URL(url);
const bridgeUrl = new URL(win.Capacitor?.getServerUrl() ?? '');
const isHttps = proxyUrl.protocol === 'https:';
const originalHost = encodeURIComponent(proxyUrl.host);
const originalPathname = proxyUrl.pathname;
proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.hostname = bridgeUrl.hostname;
proxyUrl.port = bridgeUrl.port;
proxyUrl.pathname = `${
bridgeUrl.search = proxyUrl.search;
bridgeUrl.hash = proxyUrl.hash;
bridgeUrl.pathname = `${
isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR
}/${originalHost}${originalPathname}`;
return proxyUrl.toString();
}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`;
return bridgeUrl.toString();
};

const initBridge = (w: any): void => {
Expand Down
11 changes: 4 additions & 7 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ var nativeBridge = (function (exports) {
const proxyUrl = new URL(url);
const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : '');
const isHttps = proxyUrl.protocol === 'https:';
const originalHost = encodeURIComponent(proxyUrl.host);
const originalPathname = proxyUrl.pathname;
proxyUrl.protocol = bridgeUrl.protocol;
proxyUrl.hostname = bridgeUrl.hostname;
proxyUrl.port = bridgeUrl.port;
proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`;
return proxyUrl.toString();
bridgeUrl.search = proxyUrl.search;
bridgeUrl.hash = proxyUrl.hash;
bridgeUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${encodeURIComponent(proxyUrl.host)}${proxyUrl.pathname}`;
return bridgeUrl.toString();
};
const initBridge = (w) => {
const getPlatformId = (win) => {
Expand Down

0 comments on commit 30a32f4

Please sign in to comment.