Added API for externalAPI, added env for clients

This commit is contained in:
SepehrYahyaee
2026-06-13 11:26:33 +03:30
parent cb47069e90
commit 3abbd45fac
13 changed files with 335 additions and 161 deletions

View File

@@ -0,0 +1,75 @@
import {
IsBooleanString,
IsEnum,
IsNumber,
IsPositive,
IsString,
IsUrl,
Matches,
Max,
Min,
MinLength,
} from "class-validator";
import { StringValue } from "ms";
export enum Environment {
Development = "development",
Production = "production",
}
export class EnvironmentVariables {
@IsEnum(Environment, {
message: "NODE_ENV should be development or production",
})
NODE_ENV: Environment;
// --------------------------------------------------------- //
@IsNumber(
{
allowNaN: false,
allowInfinity: false,
},
{
message: "PORT must be a valid number",
},
)
@IsPositive({ message: "PORT must be positive" })
@Min(0, { message: "PORT must be between 0 and 65535" })
@Max(65535, { message: "PORT must be between 0 and 65535" })
PORT: number;
// --------------------------------------------------------- //
@IsString({ message: "MONGO_URI must be string" })
@IsUrl(
{
require_tld: false,
protocols: ["mongodb", "mongodb+srv"],
},
{
message: "MONGO_URI must be in the correct format (mongodb://...)",
},
)
MONGO_URI: string;
// --------------------------------------------------------- //
@IsBooleanString({ message: "MONGO_TLS must be boolean" })
MONGO_TLS: string;
// --------------------------------------------------------- //
@IsBooleanString({ message: "MONGO_TLS_ALLOW_INVALID_CERTS must be boolean" })
MONGO_TLS_ALLOW_INVALID_CERTS: string;
// --------------------------------------------------------- //
@IsString({ message: "JWT_SECRET must be string" })
@MinLength(32, {
message: "JWT_SECRET must be at least 32 characters",
})
JWT_SECRET: string;
// --------------------------------------------------------- //
@Matches(/^\d+(ms|s|m|h|d|w|y)$/, {
message: "JWT_EXPIRY must be in the correct format",
})
JWT_EXPIRY: StringValue;
// --------------------------------------------------------- //
// @IsString({ message: "HASH_PEPPER must be string" })
// @MinLength(32, {
// message: "HASH_PEPPER must be at least 32 characters",
// })
// HASH_PEPPER: string;
// --------------------------------------------------------- //
}