From 78e543d32128d8d7f30ac1c64f6b4bd7b0260092 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 2 Jun 2025 22:54:44 +0100 Subject: [PATCH] feat: add next public envs to runtime --- .dockerignore | 2 ++ .gitignore | 3 +++ apps/web/Dockerfile | 7 ------- apps/web/next.config.js | 6 +++++- apps/web/package.json | 1 + apps/web/src/pages/_app.tsx | 7 ++++--- .../web/src/pages/api/stripe/create_billing_session.ts | 3 ++- .../src/pages/api/stripe/create_checkout_session.ts | 5 +++-- apps/web/src/pages/api/upload/image.ts | 5 ++--- apps/web/src/utils/helpers.ts | 4 ++-- apps/web/src/views/settings/components/Avatar.tsx | 4 ++-- apps/web/src/views/settings/index.tsx | 3 ++- docker-compose.yml | 8 +------- packages/api/src/openapi.ts | 3 ++- packages/auth/src/auth.ts | 3 ++- packages/email/src/templates/join-workspace.tsx | 3 ++- packages/email/src/templates/magic-link.tsx | 3 ++- pnpm-lock.yaml | 10 ++++++++++ 18 files changed, 47 insertions(+), 33 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9bdaea27..448021a8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ .env +docker-compose.override.yml + Dockerfile ./**/*/Dockerfile diff --git a/.gitignore b/.gitignore index 7c60a2e1..50a503cc 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ dist/ # turbo .turbo + +# docker +docker-compose.override.yml diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index da66087f..1105ec0a 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -42,13 +42,6 @@ ENV CI=true WORKDIR /app -ARG NEXT_PUBLIC_KAN_ENV=${NEXT_PUBLIC_KAN_ENV} -ARG NEXT_PUBLIC_UMAMI_ID=${NEXT_PUBLIC_UMAMI_ID} -ARG NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL} -ARG NEXT_PUBLIC_STORAGE_URL=${NEXT_PUBLIC_STORAGE_URL} -ARG NEXT_PUBLIC_STORAGE_DOMAIN=${NEXT_PUBLIC_STORAGE_DOMAIN} -ARG NEXT_PUBLIC_AVATAR_BUCKET_NAME=${NEXT_PUBLIC_AVATAR_BUCKET_NAME} - # Copy lockfile and package.json's of isolated subworkspace COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 908318a9..295d9485 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -1,9 +1,13 @@ import { fileURLToPath } from "url"; import createJiti from "jiti"; +import { env } from "next-runtime-env"; +import { configureRuntimeEnv } from "next-runtime-env/build/configure.js"; // Import env files to validate at build time. Use jiti so we can load .ts files in here. createJiti(fileURLToPath(import.meta.url))("./src/env"); +configureRuntimeEnv(); + /** @type {import("next").NextConfig} */ const config = { reactStrictMode: true, @@ -22,7 +26,7 @@ const config = { typescript: { ignoreBuildErrors: true }, images: { - domains: [process.env.NEXT_PUBLIC_STORAGE_DOMAIN ?? ""], + domains: [env("NEXT_PUBLIC_STORAGE_DOMAIN") ?? ""], }, experimental: { instrumentationHook: true, diff --git a/apps/web/package.json b/apps/web/package.json index 05267c90..f7912eb5 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -35,6 +35,7 @@ "jwt-decode": "^4.0.0", "next": "^14.2.15", "next-logger": "^5.0.1", + "next-runtime-env": "^1.7.2", "nextjs-cors": "^2.2.0", "pino": "^9.6.0", "react": "catalog:react18", diff --git a/apps/web/src/pages/_app.tsx b/apps/web/src/pages/_app.tsx index 1fedd09f..480a955b 100644 --- a/apps/web/src/pages/_app.tsx +++ b/apps/web/src/pages/_app.tsx @@ -2,8 +2,8 @@ import "~/styles/globals.css"; import type { AppType } from "next/app"; import { Plus_Jakarta_Sans } from "next/font/google"; +import { env } from "next-runtime-env"; -import { env } from "~/env"; import { ModalProvider } from "~/providers/modal"; import { PopupProvider } from "~/providers/popup"; import { ThemeProvider } from "~/providers/theme"; @@ -31,13 +31,14 @@ const MyApp: AppType = ({ Component, pageProps }) => { position: relative; } `} - {env.NEXT_PUBLIC_UMAMI_ID && ( + {env("NEXT_PUBLIC_UMAMI_ID") && (