mirror of
https://github.com/etiennecollin/unifi-voucher-manager.git
synced 2025-10-23 08:12:15 +00:00
fix: made wifi environment variables accessible to frontend
- Also reverted change in run_wrapper.sh where backend variables where overwritten. This is simply not an issue as variables are baked-in at build time.
This commit is contained in:
@@ -81,6 +81,10 @@ WORKDIR /app
|
||||
RUN addgroup -g 1001 -S appgroup && \
|
||||
adduser -S appuser -u 1001 -G appgroup
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY ./scripts/entrypoint.sh ./
|
||||
RUN chmod +x entrypoint.sh
|
||||
|
||||
# Copy run wrapper script
|
||||
COPY ./scripts/run_wrapper.sh ./
|
||||
RUN chmod +x run_wrapper.sh
|
||||
@@ -108,4 +112,5 @@ ENV BACKEND_BIND_PORT="8080"
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /usr/local/bin/healthcheck.sh
|
||||
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
CMD ["./run_wrapper.sh"]
|
||||
|
@@ -18,6 +18,10 @@ export default function RootLayout({
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<head>
|
||||
{/* Load runtime config */}
|
||||
<script src="/runtime-config.js"></script>
|
||||
</head>
|
||||
<body className={`antialiased`}>{children}</body>
|
||||
</html>
|
||||
);
|
||||
|
7
frontend/src/types/runtime.ts
Normal file
7
frontend/src/types/runtime.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
__RUNTIME_CONFIG__?: { [key: string]: string | undefined };
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
4
frontend/src/utils/runtimeConfig.ts
Normal file
4
frontend/src/utils/runtimeConfig.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export const getRuntimeConfig = (): Record<string, string | undefined> => {
|
||||
if (typeof window === "undefined") return {};
|
||||
return window.__RUNTIME_CONFIG__ ?? {};
|
||||
};
|
@@ -1,3 +1,5 @@
|
||||
import { getRuntimeConfig } from "@/utils/runtimeConfig";
|
||||
|
||||
type WifiType = "WPA" | "WEP" | "nopass";
|
||||
|
||||
export interface WifiConfig {
|
||||
@@ -8,10 +10,12 @@ export interface WifiConfig {
|
||||
}
|
||||
|
||||
export function generateWifiConfig(): WifiConfig {
|
||||
const ssid = process.env.NEXT_WIFI_SSID;
|
||||
const password = process.env.NEXT_WIFI_PASSWORD;
|
||||
const type = process.env.NEXT_WIFI_TYPE;
|
||||
const hidden = process.env.NEXT_WIFI_HIDDEN;
|
||||
const {
|
||||
WIFI_SSID: ssid,
|
||||
WIFI_PASSWORD: password,
|
||||
WIFI_TYPE: type,
|
||||
WIFI_HIDDEN: hidden,
|
||||
} = getRuntimeConfig();
|
||||
|
||||
if (ssid == null) {
|
||||
throw "No SSID provided, use the environment variable WIFI_SSID to set one";
|
||||
|
25
scripts/entrypoint.sh
Normal file
25
scripts/entrypoint.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
# Set variables accessible by the frontend
|
||||
mkdir -p /app/frontend/public
|
||||
|
||||
# Build runtime-config.js containing only env vars that are defined and non-empty.
|
||||
node - <<'NODE'
|
||||
const fs = require('fs');
|
||||
const outPath = '/app/frontend/public/runtime-config.js';
|
||||
const keys = ['WIFI_SSID','WIFI_PASSWORD','WIFI_TYPE','WIFI_HIDDEN'];
|
||||
const cfg = {};
|
||||
for (const k of keys) {
|
||||
const v = process.env[k];
|
||||
if (v !== undefined) {
|
||||
cfg[k] = v;
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(outPath, 'window.__RUNTIME_CONFIG__ = ' + JSON.stringify(cfg) + ';', 'utf8');
|
||||
console.log('WROTE', outPath, 'keys=', Object.keys(cfg));
|
||||
NODE
|
||||
|
||||
# exec the original command
|
||||
exec "$@"
|
@@ -17,8 +17,7 @@ sleep 3
|
||||
# Start frontend in foreground
|
||||
echo "Starting frontend..."
|
||||
NEXT_TELEMETRY_DISABLED="1" NODE_ENV="production" \
|
||||
HOSTNAME=${FRONTEND_BIND_HOST} PORT="${FRONTEND_BIND_PORT}" \
|
||||
UNIFI_CONTROLLER_URL="" UNIFI_API_KEY="" UNIFI_SITE_ID="" \
|
||||
HOSTNAME="${FRONTEND_BIND_HOST}" PORT="${FRONTEND_BIND_PORT}" \
|
||||
node ./frontend/server.js &
|
||||
FRONTEND_PID=$!
|
||||
|
||||
|
Reference in New Issue
Block a user