move database configs to .env
This commit is contained in:
@@ -2,4 +2,7 @@ ENV=development
|
|||||||
PORT=5000
|
PORT=5000
|
||||||
SECRET=aE8efkEP8+V/ibEQl8IKbw==
|
SECRET=aE8efkEP8+V/ibEQl8IKbw==
|
||||||
|
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=postgres
|
||||||
DB_NAME=todoListDev
|
DB_NAME=todoListDev
|
||||||
@@ -2,4 +2,7 @@ ENV=test
|
|||||||
PORT=5000
|
PORT=5000
|
||||||
SECRET=aE8efkEP8+V/ibEQl8IKbw==
|
SECRET=aE8efkEP8+V/ibEQl8IKbw==
|
||||||
|
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER=postgres
|
||||||
|
DB_PASSWORD=postgres
|
||||||
DB_NAME=todoListTest
|
DB_NAME=todoListTest
|
||||||
3
server/src/env.d.ts
vendored
3
server/src/env.d.ts
vendored
@@ -1,5 +1,8 @@
|
|||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
|
DB_HOST?: string;
|
||||||
|
DB_USER?: string;
|
||||||
|
DB_PASSWORD?: string;
|
||||||
DB_NAME?: string;
|
DB_NAME?: string;
|
||||||
NODE_ENV?: 'test' | 'development' | 'production';
|
NODE_ENV?: 'test' | 'development' | 'production';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from "dotenv";
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { DataSource } from "typeorm";
|
import { DataSource } from "typeorm";
|
||||||
import { Project } from "../entity/project.entity";
|
import { Project } from "../entity/project.entity";
|
||||||
import { Task } from '../entity/task.entity';
|
import { Task } from "../entity/task.entity";
|
||||||
import { User } from "../entity/user.entity";
|
import { User } from "../entity/user.entity";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config({
|
||||||
|
path: process.env.NODE_ENV === "test" ? ".env.test" : ".env",
|
||||||
|
});
|
||||||
|
|
||||||
export const AppDataSource = new DataSource({
|
export const AppDataSource = new DataSource({
|
||||||
type: "postgres",
|
type: "postgres",
|
||||||
host: "localhost",
|
host: process.env.DB_HOST,
|
||||||
port: 5432,
|
port: 5432,
|
||||||
username: "joao",
|
username: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
database: process.env.DB_NAME,
|
database: process.env.DB_NAME,
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: false,
|
logging: false,
|
||||||
entities: [User, Project, Task],
|
entities: [User, Project, Task],
|
||||||
migrations: [],
|
});
|
||||||
subscribers: [],
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user