-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-env.mjs
More file actions
21 lines (18 loc) · 755 Bytes
/
Copy pathload-env.mjs
File metadata and controls
21 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Loads `.env` / `.env.local` from the repo root so `node scripts/*.mjs` sees the
* same variables as Vite (Vite auto-loads these; plain Node does not).
*/
import dotenv from "dotenv";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.join(__dirname, "..");
dotenv.config({ path: path.join(root, ".env") });
dotenv.config({ path: path.join(root, ".env.local"), override: true });
/** Canonical origin: no trailing slash; adds https:// if the scheme is missing. */
export function normalizeSiteUrl(raw) {
let u = (raw ?? "").trim().replace(/\/+$/, "");
if (!u) return "";
if (!/^https?:\/\//i.test(u)) u = `https://${u}`;
return u;
}