From 1d0d0e7542eaccf12bef4394ea5bebb6bdf3219f Mon Sep 17 00:00:00 2001 From: Tarik Hastor Date: Mon, 19 May 2025 18:37:41 +0200 Subject: [PATCH 1/3] pokusaj --- netlify/functions/extRoute.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 netlify/functions/extRoute.js diff --git a/netlify/functions/extRoute.js b/netlify/functions/extRoute.js new file mode 100644 index 0000000..38c460f --- /dev/null +++ b/netlify/functions/extRoute.js @@ -0,0 +1,5 @@ +const axios = require('axios'); + +exports.handler = async (event, context) => { + return await axios.get(event.url); +}; From 8128b051653c5cb90724a0f3d976d8cad7a1f3d7 Mon Sep 17 00:00:00 2001 From: Tarik Hastor Date: Mon, 19 May 2025 18:45:36 +0200 Subject: [PATCH 2/3] ja nisam norm --- headers.toml | 7 +++++++ src/api/api.js | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 headers.toml diff --git a/headers.toml b/headers.toml new file mode 100644 index 0000000..357cf65 --- /dev/null +++ b/headers.toml @@ -0,0 +1,7 @@ +[functions] + directory = "netlify/functions" # Or your functions directory + +[[redirects]] + from = "/api/netlify/directions" # Client will call this path + to = "/.netlify/functions/extRoute" + status = 200 \ No newline at end of file diff --git a/src/api/api.js b/src/api/api.js index 369d695..f50e30b 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -1602,9 +1602,13 @@ export const apiExternGetOptimalRouteAsync = async (locs, transportMode) => { .join('|'); if (!origin || !destination) return; const url = `https://maps.googleapis.com/maps/api/directions/json?origin=${encodeURIComponent(origin)}&destination=${encodeURIComponent(destination)}&waypoints=optimize:true|${waypointsString}&mode=${transportMode}&key=${googleMapsApiKey}`; - + const netlifyFunctionEndpoint = `/api/netlify/directions`; console.log('Requesting directions URL:', url); - const response = await fetch(url); + const response = await axios.get(netlifyFunctionEndpoint, { + params: { + url: url, // Pass the partial URL + }, + }); if (!response.ok) throw new Error(`Error fetching route: ${response.statusText}`); From 4105f5788bd9ca1c6a0466d8d59a97ef98522529 Mon Sep 17 00:00:00 2001 From: Tarik Hastor Date: Mon, 19 May 2025 18:56:38 +0200 Subject: [PATCH 3/3] ocaj --- src/api/api.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index f50e30b..9f136c0 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -11,6 +11,7 @@ import axios from 'axios'; import * as XLSX from 'xlsx'; import ads from '../data/ads.js'; import sha256 from 'crypto-js/sha256'; +//import { GET } from 'superagent'; const baseApiUrl = import.meta.env.VITE_API_BASE_URL; const API_FLAG = import.meta.env.VITE_API_FLAG; const API_ENV_DEV = 'dev'; @@ -1604,11 +1605,12 @@ export const apiExternGetOptimalRouteAsync = async (locs, transportMode) => { const url = `https://maps.googleapis.com/maps/api/directions/json?origin=${encodeURIComponent(origin)}&destination=${encodeURIComponent(destination)}&waypoints=optimize:true|${waypointsString}&mode=${transportMode}&key=${googleMapsApiKey}`; const netlifyFunctionEndpoint = `/api/netlify/directions`; console.log('Requesting directions URL:', url); - const response = await axios.get(netlifyFunctionEndpoint, { - params: { - url: url, // Pass the partial URL - }, - }); + // const response = await axios.get(netlifyFunctionEndpoint, { + // params: { + // url: url, // Pass the partial URL + // }, + // }); + const response = await fetch(url, { method: 'GET', mode: 'no-cors' }); if (!response.ok) throw new Error(`Error fetching route: ${response.statusText}`);