Skip to content

Commit

Permalink
refact(docker): changed docker-compose + renamed folders in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Molaryy committed Sep 7, 2024
1 parent 39f0fd8 commit bff1596
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
23 changes: 23 additions & 0 deletions backend/middleware/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package middlewares

import (
"github.com/gin-gonic/gin"
"net/http"
)

type RegisterInput struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
}

func AuthController(c *gin.Context) {
var input RegisterInput

if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"message": "You just registered",
})
}
19 changes: 19 additions & 0 deletions backend/middleware/cors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package middlewares

import "github.com/gin-gonic/gin"

func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, PATCH, DELETE")

if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}

c.Next()
}
}
15 changes: 11 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ version: '3.9'

services:
database:
container_name: bective_db
container_name: db_bective
image: postgres:12.8
restart: always
env_file:
- .env
ports:
- '5432:5432'
volumes:
- db:/var/lib/postgresql/data
restart: always
backend:
container_name: bective_api
container_name: backend_bective
env_file:
- .env
build: ./backend
Expand All @@ -21,6 +21,13 @@ services:
depends_on:
- database
restart: always

frontend:
container_name: frontend_bective
build: ./frontend
ports:
- '5173:5173'
depends_on:
- backend
restart: always
volumes:
db:
33 changes: 0 additions & 33 deletions docker-test-compose.yml

This file was deleted.

0 comments on commit bff1596

Please sign in to comment.