diff --git a/admin/src/controllers/membership/blockUnblock.controller.ts b/admin/src/controllers/membership/blockUnblock.controller.ts index 15d2307..16146a1 100644 --- a/admin/src/controllers/membership/blockUnblock.controller.ts +++ b/admin/src/controllers/membership/blockUnblock.controller.ts @@ -1,7 +1,6 @@ import { Request, Response } from 'express'; import { IDependency } from '../../frameworks/types/dependency'; import { kafkaClient } from '../../config/kafka.connection'; -// import { JobUpdatedEventPublisher } from "../../frameworks/services/kafka-events/publishers/job-updated-publisher"; import { MemberShipPlanUpdatedEventPublisher } from '../../frameworks/utils/kafka-events/publishers/membership-plan-updated-publisher '; import { NotFoundError } from '@abijobportal/common'; diff --git a/auth/src/config/appConfig.ts b/auth/src/config/appConfig.ts index bfb94b9..1aa8b7d 100644 --- a/auth/src/config/appConfig.ts +++ b/auth/src/config/appConfig.ts @@ -1,4 +1,4 @@ -interface IAppConfig { +export interface IAppConfig { PORT: string | number; API_PREFIX: string; MONGO_URL_AUTH: string; diff --git a/auth/src/index.ts b/auth/src/index.ts index 7f21620..8524a09 100644 --- a/auth/src/index.ts +++ b/auth/src/index.ts @@ -2,22 +2,27 @@ import { connectDB } from './config/db.connection'; import { app } from './frameworks/express/app'; import { UserUpdatedEventConsumer } from './frameworks/utils/kafka-events/consumers/user-updated-consumer'; import { kafkaClient } from './config/kafka.connection'; -import { appConfig } from './config/appConfig'; +import { appConfig, IAppConfig } from './config/appConfig'; const start = async () => { console.log('Starting up....'); - if (!process.env.JWT_SECRET_KEY) throw new Error('JWT_SECRET_KEY must be defined'); - - if (!appConfig.JWT_REFRESH_SECRET_KEY) throw new Error('JWT_REFRESH_SECRET_KEY must be defined'); - - if (!appConfig.MONGO_URL_AUTH) throw new Error('MONGO_URL_AUTH must be defined'); - - if (!appConfig.TWILIO_AUTH_TOKEN) throw new Error('TWILIO_AUTH_TOKEN must be defined'); - - if (!appConfig.TWILIO_ACCOUNT_SID) throw new Error('TWILIO_ACCOUNT_SID must be defined'); - - if (!appConfig.TWILIO_SERVICE_SID) throw new Error('TWILIO_SERVICE_SID must be defined'); + // Env checking + const REQUIRED_ENV_VARIABLES = (Object.keys(appConfig) as (keyof IAppConfig)[]) + + const missingEnvVariables: string[] = REQUIRED_ENV_VARIABLES.filter((key: keyof IAppConfig) => { + const value: string | number | string[] = appConfig[key]; + return !value || (Array.isArray(value) && !value.length); + }); + + if (missingEnvVariables.length) { + // eslint-disable-next-line no-console + console.error( + `🚨 Missing the following required environment variable${missingEnvVariables.length === 1 ? '' : 's'}: ` + + `${missingEnvVariables.map((variable) => `"${variable}"`).join(', ')} `, + ); + process.exit(1); + } // to connect to mongodb await connectDB(); diff --git a/chat/src/config/appConfig.ts b/chat/src/config/appConfig.ts index 9c5adc1..e600184 100644 --- a/chat/src/config/appConfig.ts +++ b/chat/src/config/appConfig.ts @@ -1,4 +1,4 @@ -interface IAppConfig { +export interface IAppConfig { PORT: string | number; API_PREFIX: string; MONGO_URL_CHAT: string; diff --git a/chat/src/index.ts b/chat/src/index.ts index 62ba014..9793439 100644 --- a/chat/src/index.ts +++ b/chat/src/index.ts @@ -1,4 +1,4 @@ -import { appConfig } from './config/appConfig'; +import { appConfig, IAppConfig } from './config/appConfig'; import { connectDB } from './config/db.connection'; import { kafkaClient } from './config/kafka.connection'; import { httpServer } from './frameworks/express/app'; @@ -10,9 +10,22 @@ import { setupSocketIO } from './frameworks/webSocket/socket'; const start = async () => { console.log('chat service Starting up....'); - if (!appConfig.MONGO_URL_CHAT) throw new Error('MONGO_URL_CHAT must be defined'); - if (!appConfig.JWT_SECRET_KEY) throw new Error('JWT_SECRET_KEY must be defined'); - if (!appConfig.JWT_REFRESH_SECRET_KEY) throw new Error('JWT_REFRESH_SECRET_KEY must be defined'); + // Env checking + const REQUIRED_ENV_VARIABLES = (Object.keys(appConfig) as (keyof IAppConfig)[]) + + const missingEnvVariables: string[] = REQUIRED_ENV_VARIABLES.filter((key: keyof IAppConfig) => { + const value: string | number | string[] = appConfig[key]; + return !value || (Array.isArray(value) && !value.length); + }); + + if (missingEnvVariables.length) { + // eslint-disable-next-line no-console + console.error( + `🚨 Missing the following required environment variable${missingEnvVariables.length === 1 ? '' : 's'}: ` + + `${missingEnvVariables.map((variable) => `"${variable}"`).join(', ')} `, + ); + process.exit(1); + } console.log('before socket instance'); setupSocketIO(httpServer); diff --git a/job/src/config/appConfig.ts b/job/src/config/appConfig.ts index 73f3efc..ddd1775 100644 --- a/job/src/config/appConfig.ts +++ b/job/src/config/appConfig.ts @@ -1,4 +1,4 @@ -interface IAppConfig { +export interface IAppConfig { PORT: string | number; API_PREFIX: string; MONGO_URL_JOB: string; diff --git a/job/src/index.ts b/job/src/index.ts index befa7eb..40a09e6 100644 --- a/job/src/index.ts +++ b/job/src/index.ts @@ -4,16 +4,27 @@ import { kafkaClient } from './config/kafka.connection'; import { jobUpdatedEventConsumer } from './frameworks/utils/kafka-events/consumers/jobUpdatedConsumer'; import { UserCreatedEventConsumer } from './frameworks/utils/kafka-events/consumers/userCreatedConsumer'; import { UserUpdatedEventConsumer } from './frameworks/utils/kafka-events/consumers/userUpdatedConsumer'; -import { appConfig } from './config/appConfig'; +import { appConfig, IAppConfig } from './config/appConfig'; const start = async () => { console.log('Job service Starting up....'); - if (!appConfig.JWT_SECRET_KEY) throw new Error('JWT_SECRET_KEY must be defined'); + // Env checking + const REQUIRED_ENV_VARIABLES = (Object.keys(appConfig) as (keyof IAppConfig)[]) - if (!appConfig.JWT_REFRESH_SECRET_KEY) throw new Error('JWT_REFRESH_SECRET_KEY must be defined'); + const missingEnvVariables: string[] = REQUIRED_ENV_VARIABLES.filter((key: keyof IAppConfig) => { + const value: string | number | string[] = appConfig[key]; + return !value || (Array.isArray(value) && !value.length); + }); - if (!appConfig.MONGO_URL_JOB) throw new Error('MONGO_URL_JOB must be defined'); + if (missingEnvVariables.length) { + // eslint-disable-next-line no-console + console.error( + `🚨 Missing the following required environment variable${missingEnvVariables.length === 1 ? '' : 's'}: ` + + `${missingEnvVariables.map((variable) => `"${variable}"`).join(', ')} `, + ); + process.exit(1); + } await connectDB(); @@ -22,9 +33,9 @@ const start = async () => { const userUpdatedEvent = new UserUpdatedEventConsumer(kafkaClient); const jobUpdatedEvent = new jobUpdatedEventConsumer(kafkaClient); - // await userUpdatedEvent.subscribe(); - // await userCreatedEvent.subscribe(); - // await jobUpdatedEvent.subscribe(); + await userUpdatedEvent.subscribe(); + await userCreatedEvent.subscribe(); + await jobUpdatedEvent.subscribe(); app.listen(appConfig.PORT, () => { console.log(`job service Listening on port ${appConfig.PORT}....`); diff --git a/payment/src/config/appConfig.ts b/payment/src/config/appConfig.ts index a762cbc..f4d93f9 100644 --- a/payment/src/config/appConfig.ts +++ b/payment/src/config/appConfig.ts @@ -1,4 +1,4 @@ -interface IAppConfig { +export interface IAppConfig { PORT: string | number; API_PREFIX: string; MONGO_URL_PAYMENT: string; diff --git a/payment/src/index.ts b/payment/src/index.ts index a43322e..2e9ae6f 100644 --- a/payment/src/index.ts +++ b/payment/src/index.ts @@ -2,18 +2,28 @@ import { connectDB } from './config/db.connection'; import { app } from './frameworks/express/app'; import { kafkaClient } from './config/kafka.connection'; import { MembershipPlanCreatedEventConsumer } from './frameworks/utils/kafka-events/consumers/premiumPlanCreatedConsumer'; -import { appConfig } from './config/appConfig'; +import { appConfig, IAppConfig } from './config/appConfig'; const start = async () => { console.log('Starting up profile....'); - if (!appConfig.JWT_SECRET_KEY) throw new Error('JWT_SECRET_KEY must be defined'); + // Env checking + const REQUIRED_ENV_VARIABLES = (Object.keys(appConfig) as (keyof IAppConfig)[]) - if (!appConfig.JWT_REFRESH_SECRET_KEY) throw new Error('JWT_REFRESH_SECRET_KEY must be defined'); + const missingEnvVariables: string[] = REQUIRED_ENV_VARIABLES.filter((key: keyof IAppConfig) => { + const value: string | number | string[] = appConfig[key]; + return !value || (Array.isArray(value) && !value.length); + }); - if (!appConfig.MONGO_URL_PAYMENT) throw new Error('MONGO_URL_PROFILE must be defined'); + if (missingEnvVariables.length) { + // eslint-disable-next-line no-console + console.error( + `🚨 Missing the following required environment variable${missingEnvVariables.length === 1 ? '' : 's'}: ` + + `${missingEnvVariables.map((variable) => `"${variable}"`).join(', ')} `, + ); + process.exit(1); + } - if (!appConfig.STRIPE_SECRET_KEY) throw new Error('STRIPE_SECRET_KEY must be defined'); const membershipPlanCreatedEvent = new MembershipPlanCreatedEventConsumer(kafkaClient); diff --git a/profile/src/config/appConfig.ts b/profile/src/config/appConfig.ts index 2448cd3..5ad37cc 100644 --- a/profile/src/config/appConfig.ts +++ b/profile/src/config/appConfig.ts @@ -1,4 +1,4 @@ -interface IAppConfig { +export interface IAppConfig { PORT: string | number; API_PREFIX: string; MONGO_URL_PROFILE: string; diff --git a/profile/src/index.ts b/profile/src/index.ts index 61480a0..40c2685 100644 --- a/profile/src/index.ts +++ b/profile/src/index.ts @@ -4,22 +4,27 @@ import { UserCreatedEventConsumer } from './frameworks/utils/kafka-events/consum import { UserUpdatedEventConsumer } from './frameworks/utils/kafka-events/consumers/user-updated-consumer'; import { kafkaClient } from './config/kafka.connection'; import { paymentCreatedEventConsumer } from './frameworks/utils/kafka-events/consumers/payment-created-consumer'; -import { appConfig } from './config/appConfig'; +import { appConfig, IAppConfig } from './config/appConfig'; const start = async () => { console.log('Starting up profile....'); - if (!appConfig.JWT_SECRET_KEY) throw new Error('JWT_SECRET_KEY must be defined'); - - if (!appConfig.JWT_REFRESH_SECRET_KEY) throw new Error('JWT_REFRESH_SECRET_KEY must be defined'); - - if (!appConfig.MONGO_URL_PROFILE) throw new Error('MONGO_URL_PROFILE must be defined'); - - if (!appConfig.CLOUDINARY_API_KEY) throw new Error('CLOUDINARY_API_KEY must be defined'); - - if (!appConfig.CLOUDINARY_API_SECRET) throw new Error('CLOUDINARY_API_SECRET must be defined'); - - if (!appConfig.CLOUDINARY_CLOUD_NAME) throw new Error('CLOUDINARY_CLOUD_NAME must be defined'); + // Env checking + const REQUIRED_ENV_VARIABLES = (Object.keys(appConfig) as (keyof IAppConfig)[]) + + const missingEnvVariables: string[] = REQUIRED_ENV_VARIABLES.filter((key: keyof IAppConfig) => { + const value: string | number | string[] = appConfig[key]; + return !value || (Array.isArray(value) && !value.length); + }); + + if (missingEnvVariables.length) { + // eslint-disable-next-line no-console + console.error( + `🚨 Missing the following required environment variable${missingEnvVariables.length === 1 ? '' : 's'}: ` + + `${missingEnvVariables.map((variable) => `"${variable}"`).join(', ')} `, + ); + process.exit(1); + } await connectDB();