Add environment variable validation and parsing

Adds a validation schema for the application's environment variables using the Zod library. The parsed environment variables are then exported as constants that can be imported throughout the application, replacing the direct use of process.env.
This commit is contained in:
Aaron William Po
2023-04-06 23:38:03 -04:00
parent 6b65e09c17
commit 0d3785ad1a
21 changed files with 171 additions and 69 deletions

View File

@@ -1,16 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { v2 as cloudinary } from 'cloudinary';
import { CloudinaryStorage } from 'multer-storage-cloudinary';
import ServerError from '../util/ServerError';
const { CLOUDINARY_CLOUD_NAME, CLOUDINARY_KEY, CLOUDINARY_SECRET } = process.env;
if (!(CLOUDINARY_CLOUD_NAME && CLOUDINARY_KEY && CLOUDINARY_SECRET)) {
throw new ServerError(
'The cloudinary credentials were not found in the environment variables.',
500,
);
}
import { CLOUDINARY_CLOUD_NAME, CLOUDINARY_KEY, CLOUDINARY_SECRET } from '../env';
cloudinary.config({
cloud_name: CLOUDINARY_CLOUD_NAME,