@@ -15,6 +15,11 @@ import {
1515 ValidMinusxRootClass ,
1616} from 'extension/types'
1717import { 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+
108122export const queryURL = ( ) => sendMessage ( 'queryURL' , [ ] )
109123export const getMXToken = ( ) => sendMessage ( 'getMXToken' , [ ] )
110124export const getMetabaseState = ( path : Parameters < typeof get > [ 1 ] ) =>
0 commit comments