Skip to content

Commit f865ac7

Browse files
fix: adding single .env for all services
1 parent 120fc5a commit f865ac7

File tree

12 files changed

+56
-34
lines changed

12 files changed

+56
-34
lines changed

.env.example

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1-
# app
2-
DATABASE_URL="mysql://root:123@localhost:3306/microdb"
3-
LOGGER_URL="http://localhost:4001"
4-
API_PORT=4000
1+
# ==============================================
2+
# ENVIRONMENT CONFIGURATION
3+
# Single Source of Truth for All Services
4+
# ==============================================
5+
6+
# ==============================================
7+
# APPLICATION ENVIRONMENT
8+
# ==============================================
9+
NODE_ENV=development
510

6-
# Gateway
11+
# ==============================================
12+
# SERVICE PORTS
13+
# ==============================================
14+
API_PORT=4000
715
GATEWAY_PORT=3000
16+
LOGGER_PORT=4001
17+
818
LOG_DIR=./logs
919

10-
#logger
11-
LOGGER_PORT=4001
12-
API_URL=http://localhost:4000
20+
# ==============================================
21+
# SERVICE URLS
22+
# ==============================================
23+
API_URL=http://localhost:4000
24+
GATEWAY_URL=http://localhost:3000
25+
LOGGER_URL=http://localhost:4001
26+
27+
# ==============================================
28+
# DATABASE CONFIGURATION (API Service)
29+
# ==============================================
30+
DATABASE_URL="mysql://username:password@host:port/databasename"
31+
32+
# ==============================================
33+
# LOGGING CONFIGURATION
34+
# ==============================================
35+
LOG_LEVEL=info
36+
37+
# ==============================================
38+
# CORS CONFIGURATION
39+
# ==============================================
40+
CORS_ORIGINS=http://localhost:3000,http://localhost:4000,http://localhost:4001

apps/api/.env

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build": "nest build",
1010
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1111
"start": "nest start",
12-
"start:dev": "nest start --watch",
12+
"start:dev": "nest start --watch --env-file ../../.env",
1313
"start:debug": "nest start --debug --watch",
1414
"start:prod": "node dist/main",
1515
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",

apps/api/src/app.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import { AppService } from './app.service';
44
import { UserModule } from './user/user.module';
55
import { PrismaModule } from 'prisma/prisma.module';
66
import { LoggerModule } from './infrastructure/logger.module';
7+
import { ConfigModule } from '@nestjs/config';
78

89
@Module({
9-
imports: [UserModule, PrismaModule, LoggerModule], // LoggerModule available globally
10+
imports: [ConfigModule.forRoot({
11+
envFilePath: "../../../.env",
12+
}),
13+
PrismaModule,
14+
UserModule,
15+
LoggerModule
16+
], // LoggerModule available globally
1017
controllers: [AppController],
1118
providers: [AppService],
1219
})

apps/api/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppModule } from './app.module';
33

44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
6-
await app.listen(process.env.PORT ?? 4000);
6+
console.log("process.env.PORTs", process.env.API_PORT)
7+
await app.listen(process.env.API_PORT ?? 4000);
78
}
89
bootstrap();

apps/gateway/.env

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/gateway/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build": "nest build",
1010
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1111
"start": "nest start",
12-
"start:dev": "nest start --watch",
12+
"start:dev": "nest start --watch --env-file ../../.env",
1313
"start:debug": "nest start --debug --watch",
1414
"start:prod": "node dist/main",
1515
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",

apps/gateway/src/app.module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
4-
4+
import { ConfigModule } from '@nestjs/config';
55
@Module({
6-
imports: [],
6+
imports: [ConfigModule.forRoot({
7+
envFilePath: "../../../.env",
8+
})],
79
controllers: [AppController],
810
providers: [AppService],
911
})
10-
export class AppModule {}
12+
export class AppModule { }

apps/gateway/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { apiProxy } from './routes/api-proxy';
55
async function bootstrap() {
66
const app = await NestFactory.create(AppModule);
77
app.use('/api', apiProxy);
8-
await app.listen(process.env.PORT ?? 3000);
8+
await app.listen(process.env.GATEWAY_PORT ?? 3000);
99
}
1010
bootstrap();

apps/logger/.env

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)