next.config.mjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { existsSync, readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. // Expose the monorepo-root .env to server-side `process.env.*` reads.
  4. //
  5. // IMPORTANT: do NOT put these into `nextConfig.env`. The `env` config key is
  6. // inlined into the JS bundle at BUILD time, which (a) bakes build-time values
  7. // into the image and ignores the container's runtime environment
  8. // (docker-compose `environment:` / k8s envFrom), and (b) inlines secrets into
  9. // the bundle. Assigning to process.env here runs at config-load (build and
  10. // `next start`); in the container there is no .env (it isn't copied into the
  11. // runtime image — see .dockerignore), so this is a no-op there and the
  12. // container's injected env vars are used as-is. Real/container env always wins
  13. // — .env only fills keys that are still undefined.
  14. const envPath = resolve(import.meta.dirname, "../../.env");
  15. if (existsSync(envPath)) {
  16. const content = readFileSync(envPath, "utf-8");
  17. for (const line of content.split("\n")) {
  18. const trimmed = line.trim();
  19. if (!trimmed || trimmed.startsWith("#")) continue;
  20. const eq = trimmed.indexOf("=");
  21. if (eq < 0) continue;
  22. const key = trimmed.slice(0, eq).trim();
  23. if (!key) continue;
  24. const val = trimmed.slice(eq + 1).trim();
  25. if (process.env[key] === undefined) process.env[key] = val;
  26. }
  27. }
  28. /** @type {import('next').NextConfig} */
  29. const nextConfig = {
  30. transpilePackages: ["@pipeline/shared", "@pipeline/core", "@pipeline/tts"],
  31. };
  32. export default nextConfig;