Skip to content

Commit 645370d

Browse files
committed
feat: proxyUrl added in props
proxyUrl added in props, for backend internal google apis usage purposes.
1 parent e6ea98b commit 645370d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/GooglePlacesTextInput.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ const styles = StyleSheet.create({
6969
},
7070
});
7171

72+
const DEFAULT_GOOGLE_API_URL =
73+
'https://places.googleapis.com/v1/places:autocomplete';
7274
const GooglePlacesTextInput = forwardRef(
7375
(
7476
{
7577
apiKey,
7678
value,
7779
placeHolderText,
80+
proxyUrl,
7881
languageCode,
7982
includedRegionCodes,
8083
types = [],
@@ -136,22 +139,20 @@ const GooglePlacesTextInput = forwardRef(
136139

137140
try {
138141
setLoading(true);
139-
const response = await fetch(
140-
'https://places.googleapis.com/v1/places:autocomplete',
141-
{
142-
method: 'POST',
143-
headers: {
144-
'Content-Type': 'application/json',
145-
'X-Goog-Api-Key': apiKey,
146-
},
147-
body: JSON.stringify({
148-
input: processedText,
149-
languageCode,
150-
...(includedRegionCodes?.length > 0 && { includedRegionCodes }),
151-
...(types.length > 0 && { includedPrimaryTypes: types }),
152-
}),
153-
}
154-
);
142+
const API_URL = proxyUrl ? proxyUrl : DEFAULT_GOOGLE_API_URL;
143+
const response = await fetch(API_URL, {
144+
method: 'POST',
145+
headers: {
146+
'Content-Type': 'application/json',
147+
'X-Goog-Api-Key': apiKey,
148+
},
149+
body: JSON.stringify({
150+
input: processedText,
151+
languageCode,
152+
...(includedRegionCodes?.length > 0 && { includedRegionCodes }),
153+
...(types.length > 0 && { includedPrimaryTypes: types }),
154+
}),
155+
});
155156

156157
const data = await response.json();
157158

0 commit comments

Comments
 (0)