add WebSocket support for real-time delivery updates with JWT authentication and automatic reconnection
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/chedius/delivery-tracker/internal/auth"
|
||||
db "github.com/chedius/delivery-tracker/internal/db/sqlc"
|
||||
"github.com/chedius/delivery-tracker/internal/delivery"
|
||||
"github.com/chedius/delivery-tracker/internal/ws"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -42,7 +43,8 @@ func main() {
|
||||
|
||||
queries := db.New(pool)
|
||||
_, authHandler := initAuth(queries)
|
||||
h := delivery.NewHandler(queries)
|
||||
hub := ws.NewHub()
|
||||
h := delivery.NewHandler(queries, hub)
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
@@ -61,6 +63,7 @@ func main() {
|
||||
|
||||
r.POST("/api/auth/register", authHandler.Register)
|
||||
r.POST("/api/auth/login", authHandler.Login)
|
||||
r.GET("/api/ws", ws.HandleWS(hub, []byte(os.Getenv("JWT_SECRET"))))
|
||||
|
||||
authorized := r.Group("/api")
|
||||
authorized.Use(auth.AuthMiddleware([]byte(os.Getenv("JWT_SECRET"))))
|
||||
|
||||
Reference in New Issue
Block a user