@@ -13,8 +13,13 @@ async function addPointsLayer(map, apiBaseUrl = "http://localhost:5000") {
1313 loading . innerText = "Loading Norway points..." ;
1414 }
1515
16+ // Ensure the apiBaseUrl has proper format (not ending with slash)
17+ const normalizedBaseUrl = apiBaseUrl . endsWith ( "/" )
18+ ? apiBaseUrl . slice ( 0 , - 1 )
19+ : apiBaseUrl ;
20+
1621 // Fetch all points using pagination if necessary
17- const data = await fetchAllPoints ( apiBaseUrl , "points" ) ;
22+ const data = await fetchAllPoints ( normalizedBaseUrl , "points" ) ;
1823 console . log ( `Total points fetched: ${ data . features . length } ` ) ;
1924
2025 if ( data . features . length === 0 ) {
@@ -125,14 +130,19 @@ async function fetchAllPoints(apiBaseUrl, collectionId) {
125130 let offset = 0 ;
126131 let hasMoreData = true ;
127132
133+ // Ensure the apiBaseUrl has proper format (not ending with slash)
134+ const normalizedBaseUrl = apiBaseUrl . endsWith ( "/" )
135+ ? apiBaseUrl . slice ( 0 , - 1 )
136+ : apiBaseUrl ;
137+
128138 // Track number of requests to avoid infinite loops
129139 let requestCount = 0 ;
130140 const maxRequests = 1000 ; // Safety limit
131141
132142 while ( hasMoreData && requestCount < maxRequests ) {
133143 requestCount ++ ;
134144 // Use only the offset parameter in the URL, not limit
135- const url = `${ apiBaseUrl } /collections/${ collectionId } /items?offset=${ offset } ` ;
145+ const url = `${ normalizedBaseUrl } /collections/${ collectionId } /items?offset=${ offset } ` ;
136146 console . log ( `Fetching: ${ url } ` ) ;
137147
138148 const response = await fetch ( url ) ;
0 commit comments