diff --git a/src/GoogleAutocomplete.tsx b/src/GoogleAutocomplete.tsx index 7de76fc..b1e3d89 100644 --- a/src/GoogleAutocomplete.tsx +++ b/src/GoogleAutocomplete.tsx @@ -128,12 +128,20 @@ export const useGoogleAutocomplete = (apiKey: string, opts: Options = {}) => { }; const searchDetails = async (placeId: string) => { - return GoogleService.searchDetails(placeId, { - key: apiKey, - language, - types: queryTypes, - components: opts.components, - }); + if (isWeb && !opts.proxyUrl) { + throw new Error('A proxy url is needed for web'); + } + + return GoogleService.searchDetails( + placeId, + { + key: apiKey, + language, + types: queryTypes, + components: opts.components, + }, + opts.proxyUrl + ); }; const clearSearch = () => { diff --git a/src/services/google.service.ts b/src/services/google.service.ts index 8fe10f2..d952e7b 100644 --- a/src/services/google.service.ts +++ b/src/services/google.service.ts @@ -137,14 +137,17 @@ export class GoogleService { public static async searchDetails( placeid: string, - query: Query & { fields?: string } + query: Query & { fields?: string }, + proxyUrl?: string ): Promise { const url = `${BASE_URL}/details/json?${queryString.stringify({ ...normalizeQuery(query), placeid, })}`; - const res = await fetch(url); + const _url = proxyUrl ? proxyUrl + url : url; + + const res = await fetch(_url); const resJson: { status: string;