Remake
Добавил авторизацию в приложение, сделал регистарцию, добавил мидлы
This commit is contained in:
+17
-9
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user