Skip to content

Commit

Permalink
fix: Dynamic api url with /env
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsukoyachi committed Oct 23, 2024
1 parent 010378b commit 314a7b9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
24 changes: 24 additions & 0 deletions cloud/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:lts AS build

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build

# Production stage
FROM nginx:stable-bookworm

# Install envsubst
RUN apt-get update && apt-get install -y gettext-base && rm -rf /var/lib/apt/lists/*

COPY --from=build /app/dist /usr/share/nginx/html

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

EXPOSE 80

ENTRYPOINT ["/docker-entrypoint.sh"]
18 changes: 18 additions & 0 deletions cloud/frontend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/env bash

# List of environment variables to include
include_vars=("ALERT_MANAGEMENT_BASE_URL" "PATIENT_MANAGEMENT_BASE_URL")

# Convert specified environment variables to JSON format
{
echo "{"
for var in "${include_vars[@]}"; do
if [ -n "${!var}" ]; then
echo "\"$var\":\"${!var}\","
fi
done
echo "}" | sed 's/,}/}/'
} > /usr/share/nginx/html/env

# Start Nginx
nginx -g "daemon off;"
13 changes: 12 additions & 1 deletion cloud/frontend/src/clients/alert-management/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ import type { Configuration } from './configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';

export const BASE_PATH = "http://localhost:8082".replace(/\/+$/, "");
export let BASE_PATH = "http://localhost:8082".replace(/\/+$/, "");

fetch("/env").then(
(response) => {
response.json().then((data) => {
BASE_PATH = data.ALERT_MANAGEMENT_BASE_URL.replace(/\/+$/, "");
});
},
(error) => {
console.error("Failed to fetch /env: ", error);
}
);

/**
*
Expand Down
12 changes: 11 additions & 1 deletion cloud/frontend/src/clients/patient-management/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ import type { Configuration } from './configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';

export const BASE_PATH = "http://localhost:8083".replace(/\/+$/, "");
export let BASE_PATH = "http://localhost:8083".replace(/\/+$/, "");

fetch("/env").then(
(response) => {
response.json().then((data) => {
BASE_PATH = data.PATIENT_MANAGEMENT_BASE_URL.replace(/\/+$/, "");
});
},
(error) => {
console.error("Failed to fetch /env: ", error);
}
);
/**
*
* @export
Expand Down
2 changes: 1 addition & 1 deletion cloud/frontend/src/components/Profil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default function Profil() {
<TableRow key={alert.id}>
<TableCell align="center">{alert.severity}</TableCell>
<TableCell align="center">{alert.message}</TableCell>
<TableCell align="center">{formatTimestamp(alert.timestamp) ?? ""}</TableCell>
<TableCell align="center">{formatTimestamp(alert.timestamp ?? "")}</TableCell>
</TableRow>
))}
</TableBody>
Expand Down

0 comments on commit 314a7b9

Please sign in to comment.