MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / loadProjectEnv

Function loadProjectEnv

demo/server/openrouter-chat.ts:15–44  ·  view source on GitHub ↗
(
  envRoot: string,
  viteEnv: Record<string, string>,
)

Source from the content-addressed store, hash-verified

13
14/** Merge Vite env with a plain .env file (e.g. C:\\Users\\win10\\Documents\\research\\.env) */
15export function loadProjectEnv(
16 envRoot: string,
17 viteEnv: Record<string, string>,
18): Record<string, string> {
19 const merged = { ...viteEnv };
20 const envPath = path.join(envRoot, ".env");
21
22 if (!fs.existsSync(envPath)) {
23 return merged;
24 }
25
26 const text = fs.readFileSync(envPath, "utf8");
27 for (const line of text.split(/\r?\n/)) {
28 const trimmed = line.trim();
29 if (!trimmed || trimmed.startsWith("#")) {
30 continue;
31 }
32 const eq = trimmed.indexOf("=");
33 if (eq === -1) {
34 continue;
35 }
36 const key = trimmed.slice(0, eq).trim();
37 const value = trimmed.slice(eq + 1).trim();
38 if (key) {
39 merged[key] = value;
40 }
41 }
42
43 return merged;
44}
45
46function readBody(req: IncomingMessage): Promise<string> {
47 return new Promise((resolve, reject) => {

Callers 1

vite.config.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected