diff --git a/backend/middleware/auth.go b/backend/middleware/auth.go new file mode 100644 index 0000000..591ce89 --- /dev/null +++ b/backend/middleware/auth.go @@ -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", + }) +} diff --git a/backend/middleware/cors.go b/backend/middleware/cors.go new file mode 100644 index 0000000..10d75fb --- /dev/null +++ b/backend/middleware/cors.go @@ -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() + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 7405586..4a8d0e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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: diff --git a/docker-test-compose.yml b/docker-test-compose.yml deleted file mode 100644 index 4a8d0e8..0000000 --- a/docker-test-compose.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: '3.9' - -services: - database: - container_name: db_bective - image: postgres:12.8 - restart: always - env_file: - - .env - ports: - - '5432:5432' - volumes: - - db:/var/lib/postgresql/data - backend: - container_name: backend_bective - env_file: - - .env - build: ./backend - ports: - - '8080:8080' - depends_on: - - database - restart: always - frontend: - container_name: frontend_bective - build: ./frontend - ports: - - '5173:5173' - depends_on: - - backend - restart: always -volumes: - db: