Ajout connexion BDD
This commit is contained in:
@@ -1,9 +1,37 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
// Fichier .env
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true, // Rend les variables dispo partout dans le backend
|
||||
envFilePath: '../../.env',
|
||||
}),
|
||||
|
||||
// Connexion BDD
|
||||
TypeOrmModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
type: 'postgres',
|
||||
host: configService.get<string>('DB_HOST'),
|
||||
port: 5432,
|
||||
username: configService.get<string>('POSTGRES_USER'),
|
||||
password: configService.get<string>('POSTGRES_PASSWORD'),
|
||||
database: configService.get<string>('POSTGRES_DB'),
|
||||
|
||||
entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
||||
|
||||
// ATTENTION : 'synchronize: true' crée/modifie tes tables automatiquement en dev.
|
||||
// À passer ABSOLUMENT à 'false' quand tu seras en production (on utilisera des migrations).
|
||||
synchronize: true,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user