Добавил авторизацию в приложение, сделал регистарцию, добавил мидлы
This commit is contained in:
2026-05-07 17:57:49 +03:00
parent 7c3b588b26
commit 87ec792fd5
8 changed files with 275 additions and 64 deletions
+17 -9
View File
@@ -8,6 +8,7 @@ import (
"viplight-mrp/database"
"viplight-mrp/handlers"
"viplight-mrp/middleware"
)
func main() {
@@ -24,7 +25,7 @@ func main() {
r.Use(func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "https://mrp.kkhome.ru")
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
@@ -32,14 +33,21 @@ func main() {
c.Next()
})
// Роуты теперь вызывают функции из handlers
r.GET("/api/parts/:id", handlers.GetPart)
r.GET("/api/parts", handlers.GetAllParts)
r.GET("/api/orders", handlers.GetsOrders)
r.POST("/api/parts", handlers.CreatePart)
r.POST("/api/parts/bulk", handlers.ImportParts)
r.PATCH("/api/parts/:id/status", handlers.UpdateStatus)
r.DELETE("/api/parts/:id", handlers.DeletePart)
r.POST("/register", handlers.Register)
r.POST("/login", handlers.Login)
protected := r.Group("/api")
protected.Use(middleware.AuthRequired())
{
protected.GET("/parts/:id", handlers.GetPart)
protected.GET("/parts", handlers.GetAllParts)
protected.GET("/orders", handlers.GetsOrders)
protected.POST("/parts", handlers.CreatePart)
protected.POST("/parts/bulk", handlers.ImportParts)
protected.PATCH("/parts/:id/status", handlers.UpdateStatus)
protected.DELETE("/parts/:id", handlers.DeletePart)
}
r.Run(":8090")
}