| 13 | |
| 14 | /** Merge Vite env with a plain .env file (e.g. C:\\Users\\win10\\Documents\\research\\.env) */ |
| 15 | export 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 | |
| 46 | function readBody(req: IncomingMessage): Promise<string> { |
| 47 | return new Promise((resolve, reject) => { |