Skip to content

Commit

Permalink
refactor: setup project mode
Browse files Browse the repository at this point in the history
  • Loading branch information
a20688392 committed Feb 1, 2023
1 parent efe390c commit 83c3e93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NODE_ENV=production

DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=cophr
Expand Down
18 changes: 17 additions & 1 deletion src/config/env.validation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { plainToInstance } from "class-transformer";
import { IsNotEmpty, IsNumber, IsString, validateSync } from "class-validator";
import {
IsEnum,
IsNotEmpty,
IsNumber,
IsString,
validateSync,
} from "class-validator";

export enum Environment {
Development = "development",
Production = "production",
Test = "test",
Provision = "provision",
}

class EnvironmentVariables {
@IsEnum(Environment)
NODE_ENV: Environment = Environment.Production;

@IsString()
@IsNotEmpty()
DB_HOST: string;
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import * as dotenv from "dotenv";

import { AppModule } from "./app.module";
import { Environment } from "./config/env.validation";

dotenv.config();
async function bootstrap() {
const app = await NestFactory.create(AppModule);
setupSwagger(app);
if (process.env.NODE_ENV !== Environment.Production) {
setupSwagger(app);
}
await app.listen(3000);
}

Expand Down

0 comments on commit 83c3e93

Please sign in to comment.