2024-12-31 11:30:29 +01:00
|
|
|
import { randomBytes } from "crypto";
|
2025-08-15 20:15:58 +02:00
|
|
|
import { z } from "zod/v4";
|
2024-12-31 11:30:29 +01:00
|
|
|
|
2025-08-29 19:58:01 +02:00
|
|
|
import { createBooleanSchema, createEnv } from "@homarr/core/infrastructure/env";
|
2025-01-14 19:03:38 +01:00
|
|
|
|
2024-12-31 11:30:29 +01:00
|
|
|
const errorSuffix = `, please generate a 64 character secret in hex format or use the following: "${randomBytes(32).toString("hex")}"`;
|
|
|
|
|
|
|
|
|
|
export const env = createEnv({
|
2025-02-18 22:54:15 +01:00
|
|
|
shared: {
|
|
|
|
|
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
|
|
|
},
|
2024-12-31 11:30:29 +01:00
|
|
|
server: {
|
|
|
|
|
SECRET_ENCRYPTION_KEY: z
|
|
|
|
|
.string({
|
2025-08-15 20:15:58 +02:00
|
|
|
error: `SECRET_ENCRYPTION_KEY is required${errorSuffix}`,
|
2024-12-31 11:30:29 +01:00
|
|
|
})
|
|
|
|
|
.min(64, {
|
|
|
|
|
message: `SECRET_ENCRYPTION_KEY has to be 64 characters${errorSuffix}`,
|
|
|
|
|
})
|
|
|
|
|
.max(64, {
|
|
|
|
|
message: `SECRET_ENCRYPTION_KEY has to be 64 characters${errorSuffix}`,
|
|
|
|
|
})
|
|
|
|
|
.regex(/^[0-9a-fA-F]{64}$/, {
|
|
|
|
|
message: `SECRET_ENCRYPTION_KEY must only contain hex characters${errorSuffix}`,
|
|
|
|
|
}),
|
2025-08-29 19:58:01 +02:00
|
|
|
NO_EXTERNAL_CONNECTION: createBooleanSchema(false),
|
2025-09-05 23:05:30 +02:00
|
|
|
ENABLE_DNS_CACHING: createBooleanSchema(false),
|
2024-12-31 11:30:29 +01:00
|
|
|
},
|
|
|
|
|
runtimeEnv: {
|
|
|
|
|
SECRET_ENCRYPTION_KEY: process.env.SECRET_ENCRYPTION_KEY,
|
2025-02-18 22:54:15 +01:00
|
|
|
NODE_ENV: process.env.NODE_ENV,
|
2025-08-29 19:58:01 +02:00
|
|
|
NO_EXTERNAL_CONNECTION: process.env.NO_EXTERNAL_CONNECTION,
|
2025-09-05 23:05:30 +02:00
|
|
|
ENABLE_DNS_CACHING: process.env.ENABLE_DNS_CACHING,
|
2024-12-31 11:30:29 +01:00
|
|
|
},
|
|
|
|
|
});
|