From 1e6df136d8202c8adf65948527f4c3e7583b338c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 4 Mar 2025 22:55:01 +0900 Subject: websocket to polling --- backend/main.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'backend/main.go') diff --git a/backend/main.go b/backend/main.go index 1218b19..3df5d83 100644 --- a/backend/main.go +++ b/backend/main.go @@ -61,29 +61,16 @@ func main() { e.Use(middleware.Recover()) taskQueue := taskqueue.NewQueue("task-db:6379") - workerServer := taskqueue.NewWorkerServer("task-db:6379", queries) + workerServer := taskqueue.NewWorkerServer("task-db:6379") - gameHubs := game.NewGameHubs(queries, taskQueue, workerServer.Results()) - err = gameHubs.RestoreFromDB(ctx) - if err != nil { - log.Fatalf("Error restoring game hubs from db %v", err) - } - defer gameHubs.Close() - sockGroup := e.Group("/phperkaigi/2025/code-battle/sock") - sockHandler := gameHubs.SockHandler() - sockGroup.GET("/golf/:gameID/play", func(c echo.Context) error { - return sockHandler.HandleSockGolfPlay(c) - }) - sockGroup.GET("/golf/:gameID/watch", func(c echo.Context) error { - return sockHandler.HandleSockGolfWatch(c) - }) + gameHub := game.NewGameHub(queries, taskQueue, workerServer) apiGroup := e.Group("/phperkaigi/2025/code-battle/api") apiGroup.Use(oapimiddleware.OapiRequestValidator(openAPISpec)) - apiHandler := api.NewHandler(queries, gameHubs) + apiHandler := api.NewHandler(queries, gameHub) api.RegisterHandlers(apiGroup, api.NewStrictHandler(apiHandler, nil)) - adminHandler := admin.NewHandler(queries, gameHubs) + adminHandler := admin.NewHandler(queries, gameHub) adminGroup := e.Group("/phperkaigi/2025/code-battle/admin") adminHandler.RegisterHandlers(adminGroup) @@ -105,15 +92,12 @@ func main() { e.POST("/phperkaigi/2025/code-battle/*", func(c echo.Context) error { return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path) }) - } - go gameHubs.Run() + // Allow access from dev server. + e.Use(middleware.CORS()) + } - go func() { - if err := workerServer.Run(); err != nil { - log.Fatal(err) - } - }() + go gameHub.Run() if err := e.Start(":80"); err != http.ErrServerClosed { log.Fatal(err) -- cgit v1.2.3-70-g09d2