-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfiguration.ts
59 lines (53 loc) · 1.3 KB
/
configuration.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';
import * as z from 'zod';
type Configuration = {
appUrl: string;
zitadel: {
url: string;
userId: string;
userToken: string;
};
resend: {
apiKey?: string;
};
};
if (process.env.DOT_ENV_PATH) {
const dotenvPath = path.join(process.cwd(), process.env.DOT_ENV_PATH);
const buffer = fs.readFileSync(dotenvPath);
const defaultConfig = dotenv.parse(buffer);
Object.entries(defaultConfig).forEach(([key, value]) => {
if (!process.env[key]) process.env[key] = value;
});
}
const configurationSchema = z.object({
appUrl: z.string(),
zitadel: z.object({
url: z.string(),
userId: z.string(),
userToken: z.string(),
}),
resend: z.object({
apiKey: z.string().optional(),
}),
});
const configuration: Configuration = {
appUrl: process.env.APP_URL as string,
zitadel: {
url: process.env.ZITADEL_URL as string,
userId: process.env.ZITADEL_SERVICE_USER_ID as string,
userToken: process.env.ZITADEL_SERVICE_USER_TOKEN as string,
},
resend: {
apiKey: process.env.RESEND_API_KEY,
},
};
try {
configurationSchema.parse(configuration);
} catch (error) {
console.error('Bad configuration.', error);
throw error;
}
export type { Configuration };
export default configuration;