Skip to content

Commit

Permalink
docker file configurado com o banco de dados
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-lima258 committed Nov 9, 2024
1 parent 71fbba3 commit 13be6bc
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 20 deletions.
17 changes: 17 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.9"

services:
postgres:
container_name: postgres-urbanize
image: "bitnami/postgresql:latest"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: api-urbanize
ports:
- "5432:5432"
volumes:
- database:/var/lib/postgresql/data

volumes:
database:
81 changes: 65 additions & 16 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
"license": "ISC",
"dependencies": {
"backend": "file:",
"express": "^4.21.1"
"cors": "^2.8.5",
"express": "^4.21.0",
"express-async-errors": "^3.1.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/express": "^5.0.0",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^22.9.0",
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
Expand Down
23 changes: 23 additions & 0 deletions backend/src/infrastructure/middlewares/error-handling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Request, Response, NextFunction } from 'express';
import { ZodError } from "zod";
import { AppError } from "../utils/AppError";

export function errorHandling(
error: any,
request: Request,
response: Response,
_: NextFunction
) {
// if the error was caused by me
if (error instanceof AppError) {
return response.status(error.statusCode).json({ message: error.message})
}
// if the error was caused by Zod
if (error instanceof ZodError) {
return response
.status(400)
.json({ message: 'Validation error', issues: error.format() })
}

return response.status(500).json({ message: error.message })
}
11 changes: 11 additions & 0 deletions backend/src/infrastructure/utils/AppError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AppError {
message: string;
statusCode: number;

constructor(message: string, statusCode: number = 400) {
this.message = message;
this.statusCode = statusCode;
}
}

export { AppError }
5 changes: 5 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import express from 'express';
import cors from 'cors';
import 'express-async-errors'
import { errorHandling } from './infrastructure/middlewares/error-handling';

const app = express();

app.use(cors());
app.use(express.json());
app.use(errorHandling);

const PORT = process.env.PORT || 3333;
app.listen(PORT, () => {
Expand Down
12 changes: 10 additions & 2 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"lib": ["ES2023"],
"target": "ES2022",

"outDir": "./build",

"paths": {
"@/*": ["./src/*"]
},

"module": "node16",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,

"strict": true,
"skipLibCheck": true
}
Expand Down

0 comments on commit 13be6bc

Please sign in to comment.