From fc8afcc3d04b53a7051104bd84a11a6126eda108 Mon Sep 17 00:00:00 2001 From: Fellipe Araujo Date: Mon, 11 Apr 2022 19:53:37 -0300 Subject: [PATCH 1/4] Remove some libraries from package.json --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index e2c707b..5fad0a1 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,6 @@ "got": "^11.8.2", "jest-sonar": "^0.2.12", "jsonwebtoken": "^8.5.1", - "mongodb": "^4.1.0", - "mongoose": "^5.13.8", "pg": "^8.7.3", "reflect-metadata": "^0.1.13", "request": "^2.88.2", From 06a7f152a228d069dbb7aedbd95002c7dd9f633b Mon Sep 17 00:00:00 2001 From: Fellipe Araujo Date: Mon, 11 Apr 2022 23:40:17 -0300 Subject: [PATCH 2/4] Configure database to deploy --- docker-compose.yml | 6 +++--- src/app.ts | 5 ++--- src/config/database.ts | 18 +++++++++--------- src/server.ts | 6 ++++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index af7c0a8..468ace3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,9 +24,9 @@ services: - db_persdata:/var/lib/db command: postgres -c port=5433 environment: - POSTGRES_USER: root - POSTGRES_PASSWORD: admin - POSTGRES_DB: user + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} networks: - default networks: diff --git a/src/app.ts b/src/app.ts index a2592fa..a6399df 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,9 +1,8 @@ +require('dotenv').config() + import express from 'express'; -import dotenv from 'dotenv'; import router from './routes/router'; -dotenv.config(); - const app = express(); app.disable('x-powered-by'); diff --git a/src/config/database.ts b/src/config/database.ts index 301419f..b009b34 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -1,14 +1,14 @@ import { FishWiki } from '../models/fishWiki'; -import { DataSource } from 'typeorm' +import { DataSource } from 'typeorm'; -export const connection = new DataSource({ - type: "postgres", - host: "db", +export const connection = new DataSource({ + type: 'postgres', + host: process.env.POSTGRES_HOST || 'db', port: 5433, - username: "root", - password: "admin", - database: "user", + username: process.env.POSTGRES_USER, + password: process.env.POSTGRES_PASSWORD, + database: process.env.POSTGRES_DB, entities: [FishWiki], synchronize: true, - logging: false -}); \ No newline at end of file + logging: false, +}); diff --git a/src/server.ts b/src/server.ts index 6ecb4e2..9176653 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,6 @@ import 'reflect-metadata'; -import { connection } from './config/database'; import app from './app'; +import { connection } from './config/database'; import fishLogSeed from './utils/seed/fishLogSeed'; connection.initialize() @@ -8,7 +8,9 @@ connection.initialize() console.log("Banco conectado!") fishLogSeed() }) -.catch((err: any) => console.log(err)); +.catch((err: any) => { + console.log(err)} +); const serverPort = process.env.PORT || 4002; From 9eb1cf9da5f790472d32fdfa8fe5c9448f75d8af Mon Sep 17 00:00:00 2001 From: Fellipe Araujo Date: Mon, 11 Apr 2022 23:45:00 -0300 Subject: [PATCH 3/4] Configure port to deploy --- src/config/database.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/database.ts b/src/config/database.ts index b009b34..5399d94 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -4,7 +4,7 @@ import { DataSource } from 'typeorm'; export const connection = new DataSource({ type: 'postgres', host: process.env.POSTGRES_HOST || 'db', - port: 5433, + port: Number(process.env.POSTGRES_PORT) || 5433, username: process.env.POSTGRES_USER, password: process.env.POSTGRES_PASSWORD, database: process.env.POSTGRES_DB, From 77200a7a84fb7d539e6597743482cfef15130271 Mon Sep 17 00:00:00 2001 From: Fellipe Araujo Date: Tue, 12 Apr 2022 18:12:59 -0300 Subject: [PATCH 4/4] Add ormconfig file and others configurations to deploy --- docker-compose.yml | 1 + ormconfig.js | 16 ++++++++++++++++ src/app.ts | 1 + src/config/database.ts | 8 ++++++++ src/server.ts | 19 ++++++++++--------- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 ormconfig.js diff --git a/docker-compose.yml b/docker-compose.yml index 468ace3..9386f0d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,7 @@ services: - db_persdata:/var/lib/db command: postgres -c port=5433 environment: + POSTGRES_HOST: ${POSTGRES_HOST} POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} diff --git a/ormconfig.js b/ormconfig.js new file mode 100644 index 0000000..33ef345 --- /dev/null +++ b/ormconfig.js @@ -0,0 +1,16 @@ +module.exports = { + url: process.env.DATABASE_URL, + type: 'postgres', + host: process.env.POSTGRES_HOST, + port: process.env.POSTGRES_PORT, + username: process.env.POSTGRES_HOST, + password: process.env.POSTGRES_HOST, + database: process.env.POSTGRES_HOST, + extra: process.env.POSTGRES_HOST + ? { + ssl: { + rejectUnauthorized: false, + }, + } + : null, +}; diff --git a/src/app.ts b/src/app.ts index a6399df..48ff345 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,4 @@ +import 'reflect-metadata'; require('dotenv').config() import express from 'express'; diff --git a/src/config/database.ts b/src/config/database.ts index 5399d94..4b0f26e 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -1,3 +1,4 @@ +import 'reflect-metadata'; import { FishWiki } from '../models/fishWiki'; import { DataSource } from 'typeorm'; @@ -11,4 +12,11 @@ export const connection = new DataSource({ entities: [FishWiki], synchronize: true, logging: false, + extra: process.env.POSTGRES_HOST + ? { + ssl: { + rejectUnauthorized: false, + }, + } + : null, }); diff --git a/src/server.ts b/src/server.ts index 9176653..e806ee2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3,17 +3,18 @@ import app from './app'; import { connection } from './config/database'; import fishLogSeed from './utils/seed/fishLogSeed'; -connection.initialize() -.then(() => { - console.log("Banco conectado!") - fishLogSeed() -}) -.catch((err: any) => { - console.log(err)} -); +connection + .initialize() + .then(() => { + console.log('Banco conectado!'); + fishLogSeed(); + }) + .catch((err: any) => { + console.log(err); + }); const serverPort = process.env.PORT || 4002; app.listen(serverPort, () => { console.log('server running on port %d', serverPort); -}); \ No newline at end of file +});