Skip to content

Commit c390032

Browse files
committed
If origin is not top level, fix fetch URL
1 parent ff9cb7e commit c390032

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

web/src/app/rpc.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {
1515
ValidMinusxRootClass,
1616
} from 'extension/types'
1717
import { get } from 'lodash'
18+
import { getOrigin } from '../helpers/origin'
19+
20+
const origin = getOrigin()
21+
const fullURL = new URL(origin)
22+
const differentBaseURL = fullURL.origin !== origin && fullURL.pathname && fullURL.pathname !== '/'
1823

1924
// Hack to handle RPC messages until we replace all instances
2025
// Once all instances are replaced, we can remove this function
@@ -101,10 +106,19 @@ export const fetchData = (
101106
body?: unknown,
102107
headers?: Record<string, string>,
103108
csrfInfo?: { cookieKey: string; headerKey: string }
104-
) =>
105-
sendMessage('fetchData', [url, method, body, headers || {}, csrfInfo], {
109+
) => {
110+
if (differentBaseURL) {
111+
if (url.startsWith('/')) {
112+
url = fullURL.pathname + url
113+
} else {
114+
url = fullURL.pathname + '/' + url
115+
}
116+
}
117+
return sendMessage('fetchData', [url, method, body, headers || {}, csrfInfo], {
106118
log_rpc: false,
107119
})
120+
}
121+
108122
export const queryURL = () => sendMessage('queryURL', [])
109123
export const getMXToken = () => sendMessage('getMXToken', [])
110124
export const getMetabaseState = (path: Parameters<typeof get>[1]) =>

0 commit comments

Comments
 (0)