Skip to content

Commit db907ac

Browse files
committed
fix apiBaseUrl path
1 parent ebc5860 commit db907ac

8 files changed

Lines changed: 35 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ When deploying in different environments (local, Kubernetes, etc.), the followin
3535
- `API_BASE_URL`: The URL where the frontend will connect to the backend API.
3636
- For local development: Not needed (will default to `http://localhost:5000`)
3737
- For Docker Compose: `http://backend:5000`
38-
- For Kubernetes/production: `/api` (path to the backend service through the ingress)
38+
- For Kubernetes/production: Use the full URL including protocol and domain, e.g., `https://your-domain.com/api` (not just the path)
3939

4040
### Kubernetes Deployment
4141

frontend/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
const apiBaseUrl =
115115
window.location.hostname === "localhost"
116116
? "http://localhost:5000"
117-
: (window.API_BASE_URL || "/api");
117+
: (window.API_BASE_URL || window.location.origin + "/api");
118118

119119
// Initialize map using the function from basemap-layer.js
120120
const map = initializeMap("map");

frontend/src/js/hazard-layer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
*/
88
function addGlobalHazardTiles(map, apiBaseUrl = "http://localhost:5000") {
99
try {
10+
// Ensure the apiBaseUrl has proper format (not ending with slash)
11+
const normalizedBaseUrl = apiBaseUrl.endsWith("/")
12+
? apiBaseUrl.slice(0, -1)
13+
: apiBaseUrl;
14+
1015
// Add vector tiles source for Global Hazard Points
1116
map.addSource("global-hazard-source", {
1217
type: "vector",
1318
tiles: [
14-
`${apiBaseUrl}/collections/hazardglobal/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
19+
`${normalizedBaseUrl}/collections/hazardglobal/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
1520
],
1621
minzoom: 0,
1722
maxzoom: 15,

frontend/src/js/hyderabad-layer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
*/
66
function addHyderabadLayer(map, apiBaseUrl = "http://localhost:5000") {
77
try {
8+
// Ensure the apiBaseUrl has proper format (not ending with slash)
9+
const normalizedBaseUrl = apiBaseUrl.endsWith("/")
10+
? apiBaseUrl.slice(0, -1)
11+
: apiBaseUrl;
12+
813
// Add vector tiles source for Hyderabad
914
map.addSource("hyderabad-source", {
1015
type: "vector",
1116
tiles: [
12-
`${apiBaseUrl}/collections/hyderabad/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
17+
`${normalizedBaseUrl}/collections/hyderabad/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
1318
],
1419
minzoom: 0,
1520
maxzoom: 16,

frontend/src/js/norway-hazard-tiles.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
*/
66
function addNorwayHazardTiles(map, apiBaseUrl = "http://localhost:5000") {
77
try {
8+
// Ensure the apiBaseUrl has proper format (not ending with slash)
9+
const normalizedBaseUrl = apiBaseUrl.endsWith("/")
10+
? apiBaseUrl.slice(0, -1)
11+
: apiBaseUrl;
12+
813
// Add vector tiles source for Norway Hazard Points
914
map.addSource("norway-hazard-source", {
1015
type: "vector",
1116
tiles: [
12-
`${apiBaseUrl}/collections/points/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
17+
`${normalizedBaseUrl}/collections/points/tiles/WebMercatorQuad/{z}/{y}/{x}?f=mvt`,
1318
],
1419
minzoom: 0,
1520
maxzoom: 15,

frontend/src/js/points-layer.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

k8s-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ spec:
8989
env:
9090
- name: API_BASE_URL
9191
# The URL where the backend API is accessible from frontend clients
92-
value: "/api"
92+
value: "https://tsunami.jye.no/api"
9393
resources:
9494
limits:
9595
cpu: "0.5"

k8s-frontend.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ spec:
2222
env:
2323
- name: API_BASE_URL
2424
# The URL where the backend API is accessible from frontend clients
25-
# This should match your ingress/service path for the backend
26-
value: "/api"
25+
# This should be the full URL including protocol and domain
26+
value: "https://tsunami.jye.no/api"
2727
resources:
2828
limits:
2929
cpu: "0.5"

0 commit comments

Comments
 (0)