create-volt 0.5.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@
8
8
  // Run under PM2 in production: pm2 start server.js --name guestbook ; pm2 log
9
9
 
10
10
  import http from "node:http";
11
+ import fs from "node:fs";
11
12
  import path from "node:path";
12
13
  import { fileURLToPath } from "node:url";
13
14
  import express from "express";
@@ -17,6 +18,17 @@ import { createMailer } from "./lib/mailer.js";
17
18
  import { createRouter } from "./router.js";
18
19
 
19
20
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
21
+
22
+ // Auto-load .env (no --env-file flag needed; works the same on Windows). Never
23
+ // overrides a variable already set in the environment.
24
+ const ENV_PATH = path.join(__dirname, ".env");
25
+ if (fs.existsSync(ENV_PATH)) {
26
+ for (const line of fs.readFileSync(ENV_PATH, "utf8").split("\n")) {
27
+ const m = line.match(/^\s*([A-Za-z0-9_]+)\s*=\s*(.*?)\s*$/);
28
+ if (m && !(m[1] in process.env)) process.env[m[1]] = m[2];
29
+ }
30
+ }
31
+
20
32
  const PORT = Number(process.env.PORT) || 26629;
21
33
 
22
34
  const store = await createStore();