Skip to content

Commit

Permalink
fix: env settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorsulcer committed Dec 6, 2023
1 parent 56dfaa1 commit a5f0432
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"dotenv": "^16.3.1",
"env-var": "^7.4.1",
"mongoose": "^8.0.2",
"mysql2": "^3.6.5",
"nodemailer": "^6.9.7",
Expand Down
2 changes: 1 addition & 1 deletion src/api/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class NotificationsService {
async findById(id: string): Promise<NotificationDocument> {
const notification = await this.notificationRepository.findById(id);
if (!notification) {
throw new NotFoundException('User not found');
throw new NotFoundException('Notification not found');
}
return notification;
}
Expand Down
16 changes: 14 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ import { EmailsModule } from './api/emails/emails.module';
import { ReactAdapter } from '@webtre/nestjs-mailer-react-adapter';
import { MailerModule } from '@nestjs-modules/mailer';
import { AuthModule } from './auth/auth.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from './config/configuration';

@Module({
imports: [
MongooseModule.forRoot(process.env.MONGO_URI, {
dbName: process.env.DB_NAME,
ConfigModule.forRoot({
envFilePath: `${process.cwd()}/.env.${process.env.NODE_ENV}`,
isGlobal: true,
load: [configuration],
}),
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
uri: configService.get<string>('MONGO_URI'),
dbName: configService.get<string>('DB_NAME'),
}),
inject: [ConfigService],
}),
MailerModule.forRoot({
transport: {
Expand Down
24 changes: 24 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as env from 'env-var';
import { Deployment, Env } from '../constants/env.constants';

export default () => ({
environment: env
.get('NODE_ENV')
.required(true)
.default(Env.PRODUCTION)
.asEnum(Object.values(Env)),
deployment: env
.get('DEPLOYMENT')
.default(Deployment.DOCKER)
.asEnum(Object.values(Deployment)),
app: {
port: env.get('PORT').default(8000).asPortNumber(),
swaggerPath: env.get('SWAGGER_PATH').default('').asString(),
},
database: {
uri: env.get('MONGO_URI').required(true).asString(),
},
common: {
urlPrefix: env.get('URL_PREFIX').required(true).default('api').asString(),
},
});
7 changes: 7 additions & 0 deletions src/constants/env.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Env {
PRODUCTION = 'production',
}

export enum Deployment {
DOCKER = 'docker',
}

0 comments on commit a5f0432

Please sign in to comment.