-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.ts
More file actions
42 lines (36 loc) · 1.16 KB
/
env.ts
File metadata and controls
42 lines (36 loc) · 1.16 KB
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
import { z } from '@hono/zod-openapi';
import { config } from 'dotenv';
import { expand } from 'dotenv-expand';
import path from 'node:path';
expand(
config({
path: path.resolve(process.cwd(), process.env.NODE_ENV === 'test' ? '.env.test' : '.env'),
})
);
const EnvSchema = z.object({
NODE_ENV: z.string().default('development'),
PORT: z.coerce.number().default(9999),
LOG_LEVEL: z
.enum(['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'])
.default('info')
.optional(),
DATABASE_URL: z.string().url(),
AUTH0_DOMAIN: z.string(),
AUTH0_AUDIENCE: z.string(),
APPLICATIONINSIGHTS_CONNECTION_STRING: z.string(),
AUTH0_M2M_CLIENT_ID: z.string(),
AUTH0_M2M_CLIENT_SECRET: z.string(),
EMAIL_SERVICE_API_KEY: z.string(),
EMAIL_SERVICE_DOMAIN: z.string(),
EMAIL_SERVICE_SENDER: z.string(),
FRONTEND_URL: z.string(),
});
export type env = z.infer<typeof EnvSchema>;
// eslint-disable-next-line ts/no-redeclare
const { data: env, error } = EnvSchema.safeParse(process.env);
if (error) {
console.error('❌ Invalid env:');
console.error(JSON.stringify(error.flatten().fieldErrors, null, 2));
process.exit(1);
}
export default env!;