book: scaffold + ch00 (execution trail as spine) — evidence exp 8-31, round 3
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const workspaceRoot = path.resolve(__dirname, "..");
|
||||
|
||||
// Load the single repo-root `.env` into process.env for dev/build/start.
|
||||
//
|
||||
// This must live in next.config (not `node --env-file=...`): Next forwards the
|
||||
// original node CLI flags to its worker processes via NODE_OPTIONS, where
|
||||
// `--env-file`/`--env-file-if-exists` are rejected. process.env set here is
|
||||
// inherited by the server workers instead.
|
||||
//
|
||||
// Existing process env always wins (e.g. Coolify or `docker --env-file`), and
|
||||
// unknown keys (e.g. SERVER_TLS) are loaded too so the runtime entrypoint and
|
||||
// the rest of the app can read them.
|
||||
const envPath = path.join(workspaceRoot, ".env");
|
||||
if (existsSync(envPath)) {
|
||||
for (const raw of readFileSync(envPath, "utf8").split("\n")) {
|
||||
const line = raw.trim();
|
||||
if (!line || line.startsWith("#")) continue;
|
||||
const eq = line.indexOf("=");
|
||||
if (eq === -1) continue;
|
||||
const key = line.slice(0, eq).trim();
|
||||
let value = line.slice(eq + 1).trim();
|
||||
if (
|
||||
(value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))
|
||||
) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
if (key && !(key in process.env)) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactCompiler: true,
|
||||
// Keep the pure-JS Postgres driver external so Turbopack doesn't re-bundle it.
|
||||
serverExternalPackages: ["pg"],
|
||||
compiler: {
|
||||
removeConsole: process.env.NODE_ENV === "production",
|
||||
},
|
||||
// Allow LAN / custom host access (e.g. http://h.lizhao.net:3000) in `next dev`.
|
||||
allowedDevOrigins: ["h.lizhao.net", "tradeac-dev.h.lizhao.net"],
|
||||
experimental: {
|
||||
serverActions: {
|
||||
allowedOrigins: ["h.lizhao.net", "tradeac-dev.h.lizhao.net", "localhost", "127.0.0.1"],
|
||||
},
|
||||
},
|
||||
turbopack: {
|
||||
root: workspaceRoot,
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
Reference in New Issue
Block a user