Skip to content

Commit 9422bc3

Browse files
committed
fix: use proxyUrl for details
1 parent 96ae04e commit 9422bc3

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/GoogleAutocomplete.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,20 @@ export const useGoogleAutocomplete = (apiKey: string, opts: Options = {}) => {
128128
};
129129

130130
const searchDetails = async (placeId: string) => {
131-
return GoogleService.searchDetails(placeId, {
132-
key: apiKey,
133-
language,
134-
types: queryTypes,
135-
components: opts.components,
136-
});
131+
if (isWeb && !opts.proxyUrl) {
132+
throw new Error('A proxy url is needed for web');
133+
}
134+
135+
return GoogleService.searchDetails(
136+
placeId,
137+
{
138+
key: apiKey,
139+
language,
140+
types: queryTypes,
141+
components: opts.components,
142+
},
143+
opts.proxyUrl
144+
);
137145
};
138146

139147
const clearSearch = () => {

src/services/google.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ export class GoogleService {
137137

138138
public static async searchDetails(
139139
placeid: string,
140-
query: Query & { fields?: string }
140+
query: Query & { fields?: string },
141+
proxyUrl?: string
141142
): Promise<GoogleLocationDetailResult> {
142143
const url = `${BASE_URL}/details/json?${queryString.stringify({
143144
...normalizeQuery(query),
144145
placeid,
145146
})}`;
146147

147-
const res = await fetch(url);
148+
const _url = proxyUrl ? proxyUrl + url : url;
149+
150+
const res = await fetch(_url);
148151

149152
const resJson: {
150153
status: string;

0 commit comments

Comments
 (0)