feature/fitlien-add-cors #9
@ -7,4 +7,5 @@ TWILIO_PHONE_NUMBER=#{TWILIO_PHONE_NUMBER}#
|
|||||||
SERVICES_RGN=#{SERVICES_RGN}#
|
SERVICES_RGN=#{SERVICES_RGN}#
|
||||||
CASHFREE_CLIENT_ID=#{CASHFREE_CLIENT_ID}#
|
CASHFREE_CLIENT_ID=#{CASHFREE_CLIENT_ID}#
|
||||||
CASHFREE_CLIENT_SECRET=#{CASHFREE_CLIENT_SECRET}#
|
CASHFREE_CLIENT_SECRET=#{CASHFREE_CLIENT_SECRET}#
|
||||||
|
GOOGLE_PLACES_API_KEY=#{GOOGLE_PLACES_API_KEY}#
|
||||||
|
|
||||||
|
|||||||
@ -410,3 +410,61 @@ export const verifyCashfreePayment = onRequest({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const getPlacesAutocomplete = onRequest({
|
||||||
|
region: '#{SERVICES_RGN}#'
|
||||||
|
}, async (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
|
try {
|
||||||
|
const { input, location, radius, types, components, sessiontoken } = request.query;
|
||||||
|
|
||||||
|
if (!input) {
|
||||||
|
response.status(400).json({
|
||||||
|
error: 'Input parameter is required for autocomplete'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiKey = process.env.GOOGLE_PLACES_API_KEY;
|
||||||
|
if (!apiKey) {
|
||||||
|
logger.error('Google Places API key is not configured');
|
||||||
|
response.status(500).json({ error: 'Server configuration error' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json';
|
||||||
|
const params: any = {
|
||||||
|
key: apiKey,
|
||||||
|
input: input
|
||||||
|
};
|
||||||
|
|
||||||
|
if (location && radius) {
|
||||||
|
params.location = location;
|
||||||
|
params.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (types) {
|
||||||
|
params.types = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (components) {
|
||||||
|
params.components = components;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sessiontoken) {
|
||||||
|
params.sessiontoken = sessiontoken;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await axios.get(url, { params });
|
||||||
|
|
||||||
|
logger.info('Google Places Autocomplete API request completed successfully');
|
||||||
|
response.json(result.data);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Error fetching place autocomplete suggestions:', error);
|
||||||
|
response.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user