@@ -179,7 +179,9 @@ const handleCompareTiles = async () => {
179179 const token = generateJWT ()
180180
181181 // Create project
182- const createResponse = await fetch (` ${import .meta .env .VITE_API_BASE_URL }/projects ` , {
182+ const apiBaseUrl = import .meta .env .PROD ? import .meta .env .VITE_API_BASE_URL : ' /api'
183+
184+ const createResponse = await fetch (` ${apiBaseUrl }/projects ` , {
183185 method: ' POST' ,
184186 headers: {
185187 ' Content-Type' : ' application/json' ,
@@ -217,7 +219,7 @@ const handleCompareTiles = async () => {
217219 const formData = new FormData ()
218220 formData .append (' file' , imageBlob )
219221
220- return fetch (` ${import . meta . env . VITE_API_BASE_URL }/projects/${projectId }/images/a ` , {
222+ return fetch (` ${apiBaseUrl }/projects/${projectId }/images/a ` , {
221223 method: ' PUT' ,
222224 headers: {
223225 ' Access-Control-Allow-Origin' : ' *' ,
@@ -233,7 +235,7 @@ const handleCompareTiles = async () => {
233235 const formData = new FormData ()
234236 formData .append (' file' , imageBlob )
235237
236- return fetch (` ${import . meta . env . VITE_API_BASE_URL }/projects/${projectId }/images/b ` , {
238+ return fetch (` ${apiBaseUrl }/projects/${projectId }/images/b ` , {
237239 method: ' PUT' ,
238240 headers: {
239241 ' Access-Control-Allow-Origin' : ' *' ,
@@ -257,29 +259,26 @@ const handleCompareTiles = async () => {
257259 }
258260 const {
259261 models : [{ id : modelId }],
260- } = await fetch (` ${import . meta . env . VITE_API_BASE_URL } ` , {
262+ } = await fetch (` ${apiBaseUrl } ` , {
261263 headers: {
262264 ' Access-Control-Allow-Origin' : ' *' ,
263265 Authorization: ` Bearer ${token } ` ,
264266 },
265267 }).then ((res ) => res .json ())
266268
267269 // Run inference
268- const inferenceResponse = await fetch (
269- ` ${import .meta .env .VITE_API_BASE_URL }/projects/${projectId }/inference ` ,
270- {
271- method: ' PUT' ,
272- headers: {
273- ' Content-Type' : ' application/json' ,
274- Authorization: ` Bearer ${token } ` ,
275- },
276- body: JSON .stringify ({
277- model: modelId ,
278- bbox: drawnExtent .value ?? [0 , 0 , 0 , 0 ],
279- images: [firstTile .thumbnailUrl , secondTile .thumbnailUrl ],
280- }),
270+ const inferenceResponse = await fetch (` ${apiBaseUrl }/projects/${projectId }/inference ` , {
271+ method: ' PUT' ,
272+ headers: {
273+ ' Content-Type' : ' application/json' ,
274+ Authorization: ` Bearer ${token } ` ,
281275 },
282- )
276+ body: JSON .stringify ({
277+ model: modelId ,
278+ bbox: drawnExtent .value ?? [0 , 0 , 0 , 0 ],
279+ images: [firstTile .thumbnailUrl , secondTile .thumbnailUrl ],
280+ }),
281+ })
283282
284283 if (! inferenceResponse .ok ) {
285284 throw new Error (` Failed to run inference: ${inferenceResponse .statusText } ` )
@@ -288,15 +287,12 @@ const handleCompareTiles = async () => {
288287 // Start polling for project status
289288 const pollInterval = setInterval (async () => {
290289 try {
291- const statusResponse = await fetch (
292- ` ${import .meta .env .VITE_API_BASE_URL }/projects/${projectId } ` ,
293- {
294- headers: {
295- ' Access-Control-Allow-Origin' : ' *' ,
296- Authorization: ` Bearer ${token } ` ,
297- },
290+ const statusResponse = await fetch (` ${apiBaseUrl }/projects/${projectId } ` , {
291+ headers: {
292+ ' Access-Control-Allow-Origin' : ' *' ,
293+ Authorization: ` Bearer ${token } ` ,
298294 },
299- )
295+ } )
300296 if (! statusResponse .ok ) {
301297 throw new Error (` Failed to fetch project status: ${statusResponse .statusText } ` )
302298 }
@@ -307,15 +303,12 @@ const handleCompareTiles = async () => {
307303 clearInterval (pollInterval )
308304
309305 // Fetch inference results
310- const resultsResponse = await fetch (
311- ` ${import .meta .env .VITE_API_BASE_URL }/projects/${projectId }/inference ` ,
312- {
313- headers: {
314- ' Access-Control-Allow-Origin' : ' *' ,
315- Authorization: ` Bearer ${token } ` ,
316- },
306+ const resultsResponse = await fetch (` ${apiBaseUrl }/projects/${projectId }/inference ` , {
307+ headers: {
308+ ' Access-Control-Allow-Origin' : ' *' ,
309+ Authorization: ` Bearer ${token } ` ,
317310 },
318- )
311+ } )
319312 if (! resultsResponse .ok ) {
320313 throw new Error (` Failed to fetch inference results: ${resultsResponse .statusText } ` )
321314 }
0 commit comments