forked from ATLBitLab/twelvecash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.js
38 lines (34 loc) · 991 Bytes
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This file is included in `/next.config.js` which ensures the app isn't built with invalid env vars.
* It has to be a `.js`-file to be imported there.
*/
const { z } = require("zod");
let domainMap = {};
if (process.env.DOMAINS) {
try {
domainMap = JSON.parse(process.env.DOMAINS);
} catch (e) {
console.error("Failed to parse DOMAIN_MAP:", e);
process.exit(1);
}
}
const envSchema = z
.object({
NETWORK: z.enum(["", "testnet", "regtest"]),
DOMAINS: z.record(z.string(), z.string()),
CF_TOKEN: z.string(),
NODE_ENV: z.enum(["development", "test", "production"]),
})
.refine(
(data) => Object.keys(data.DOMAINS).length > 0,
"Requires at least one domain: domainId pair"
);
const env = envSchema.safeParse({ ...process.env, DOMAINS: domainMap });
if (!env.success) {
console.error(
"❌ Invalid environment variables:",
JSON.stringify(env.error.format(), null, 4)
);
process.exit(1);
}
module.exports.env = env.data;