Skip to content

Commit 385e552

Browse files
committed
feat(core): export native bridge utility functions
- Export isRelativeOrProxyUrl and createProxyUrl on Capacitor global object - Update CapacitorInstance interface to include new methods - Remove TODO comments in native-bridge.ts This allows plugins and other parts of the system to use these utility functions for URL handling.
1 parent 9ca4be2 commit 385e552

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/native-bridge.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ const convertBody = async (
125125
const CAPACITOR_HTTP_INTERCEPTOR = '/_capacitor_http_interceptor_';
126126
const CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM = 'u';
127127

128-
// TODO: export as Cap function
129128
const isRelativeOrProxyUrl = (url: string | undefined): boolean =>
130129
!url || !(url.startsWith('http:') || url.startsWith('https:')) || url.indexOf(CAPACITOR_HTTP_INTERCEPTOR) > -1;
131130

132-
// TODO: export as Cap function
133131
const createProxyUrl = (url: string, win: WindowCapacitor): string => {
134132
if (isRelativeOrProxyUrl(url)) return url;
135133
const bridgeUrl = new URL(win.Capacitor?.getServerUrl() ?? '');
@@ -237,6 +235,9 @@ const initBridge = (w: any): void => {
237235
return false;
238236
};
239237

238+
cap.isRelativeOrProxyUrl = isRelativeOrProxyUrl;
239+
cap.createProxyUrl = createProxyUrl;
240+
240241
win.Capacitor = cap;
241242
};
242243

@@ -604,7 +605,7 @@ const initBridge = (w: any): void => {
604605

605606
// XHR patch
606607
interface PatchedXMLHttpRequestConstructor extends XMLHttpRequest {
607-
new (): XMLHttpRequest;
608+
new(): XMLHttpRequest;
608609
}
609610

610611
window.XMLHttpRequest = function () {

core/src/definitions-internal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ export interface CapacitorInstance extends CapacitorGlobal {
8989
* Low-level API used by the native bridge.
9090
*/
9191
withPlugin?: (pluginName: string, fn: (...args: any[]) => any) => void;
92+
93+
/**
94+
* Checks if a URL is relative or a proxy URL.
95+
*/
96+
isRelativeOrProxyUrl: (url: string | undefined) => boolean;
97+
98+
/**
99+
* Creates a proxy URL for the given URL.
100+
*/
101+
createProxyUrl: (url: string, win: WindowCapacitor) => string;
92102
}
93103

94104
export interface MessageCallData {

0 commit comments

Comments
 (0)