Skip to content

Commit

Permalink
Merge pull request #9 from fga-eps-mds/PrepareToDeploy
Browse files Browse the repository at this point in the history
Configuração do Postgres para Deploy
  • Loading branch information
ArthurPaivaT authored Apr 12, 2022
2 parents 8149750 + 77200a7 commit d288924
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ services:
- db_persdata:/var/lib/db
command: postgres -c port=5433
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: admin
POSTGRES_DB: user
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
networks:
- default
networks:
Expand Down
16 changes: 16 additions & 0 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -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,
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'reflect-metadata';
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');

Expand Down
28 changes: 18 additions & 10 deletions src/config/database.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import 'reflect-metadata';
import { FishWiki } from '../models/fishWiki';
import { DataSource } from 'typeorm'
import { DataSource } from 'typeorm';

export const connection = new DataSource({
type: "postgres",
host: "db",
port: 5433,
username: "root",
password: "admin",
database: "user",
export const connection = new DataSource({
type: 'postgres',
host: process.env.POSTGRES_HOST || 'db',
port: Number(process.env.POSTGRES_PORT) || 5433,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
entities: [FishWiki],
synchronize: true,
logging: false
});
logging: false,
extra: process.env.POSTGRES_HOST
? {
ssl: {
rejectUnauthorized: false,
},
}
: null,
});
19 changes: 11 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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()
.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);
});
});

0 comments on commit d288924

Please sign in to comment.