Skip to content

Commit 33cb44e

Browse files
authored
External config file (#31)
so it can later be replaced with a volume at runtime for the built container
1 parent 55b88e4 commit 33cb44e

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// runtime configuration for the frontend so it can easily be configured on a prebuilt container
2+
window.__APP_CONFIG__ = {
3+
BACKEND_URL: "https://cryptify.nl/api/v2",
4+
PKG_URL: "https://postguard-stable.cs.ru.nl/pkg",
5+
};

cryptify-front-end/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
2121
-->
2222
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
23+
<script src="config.js"></script>
2324
<!--
2425
Notice the use of %PUBLIC_URL% in the tags above.
2526
It will be replaced with the URL of the `public` folder during the build.
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { browserName, browserVersion, isMobile } from "react-device-detect";
1+
import {browserName, browserVersion, isMobile} from "react-device-detect";
2+
3+
type ConfigFile = {
4+
PKG_URL?: string;
5+
BACKEND_URL?: string;
6+
};
7+
const rawConfig: unknown = (window as any).__APP_CONFIG__;
8+
const configFile: ConfigFile = rawConfig && typeof rawConfig === "object" ? (rawConfig as ConfigFile) : {};
29

310
// 2GB
411
export const MAX_UPLOAD_SIZE: number = 2 * 1000 * 1000 * 1000;
@@ -10,18 +17,16 @@ export const UPLOAD_CHUNK_SIZE: number = 1024 * 1024;
1017
// progress bar smooth time in seconds.
1118
export const SMOOTH_TIME: number = 2;
1219

13-
const isStable = process.env.REACT_APP_ENV === "stable";
14-
15-
export const PKG_URL = `https://postguard-${process.env.REACT_APP_ENV}.cs.ru.nl/pkg`
20+
export const PKG_URL = configFile.PKG_URL ?? `https://postguard-${process.env.REACT_APP_ENV}.cs.ru.nl/pkg`
1621

1722
// Stable: https://cryptify.nl/api/v2
1823
// Main: https://cryptify.nl/main/api/v2
19-
export const BACKEND_URL = isStable ? "https://cryptify.nl/api/v2" : "https://cryptify.nl/main/api/v2";
24+
export const BACKEND_URL = configFile.BACKEND_URL ?? "https://cryptify.nl/api/v2";
2025

2126
export const METRICS_HEADER = {
22-
"X-PostGuard-Client-Version": `${browserName}${
23-
isMobile ? "(mobile)" : ""
24-
},${browserVersion},${process.env.REACT_APP_NAME},${
25-
process.env.REACT_APP_VERSION
26-
}`,
27+
"X-PostGuard-Client-Version": `${browserName}${
28+
isMobile ? "(mobile)" : ""
29+
},${browserVersion},${process.env.REACT_APP_NAME},${
30+
process.env.REACT_APP_VERSION
31+
}`,
2732
};

frontend.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RUN npm install --legacy-peer-deps
1616
RUN npm run build-stable
1717

1818
FROM nginx:alpine
19+
1920
COPY --from=builder /app/build /var/www/html
2021
COPY --from=builder /app/nginx.conf /etc/nginx/nginx.conf
2122

0 commit comments

Comments
 (0)