card-jong-be/main.go

44 lines
1.0 KiB
Go
Raw Normal View History

2024-05-03 15:59:20 +00:00
package main
import (
2024-05-16 21:17:41 +00:00
"card-jong-be/controller"
2024-05-03 15:59:20 +00:00
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/rs/cors"
)
func main() {
fmt.Println("hello SEKAI!!")
2024-05-21 14:09:23 +00:00
mainRouter := mux.NewRouter()
httpRouter := mainRouter.PathPrefix("/api").Subrouter()
wsRouter := mainRouter.PathPrefix("/ws").Subrouter()
2024-05-03 15:59:20 +00:00
2024-05-21 14:09:23 +00:00
// HTTP routes
2024-05-25 21:17:48 +00:00
httpRouter.HandleFunc("/register", controller.RegisterUser)
2024-05-21 14:09:23 +00:00
httpRouter.HandleFunc("/validate", controller.ValidateId)
httpRouter.HandleFunc("/lobby/new", controller.CreateLobby).Methods("POST")
// WS routes
wsRouter.HandleFunc("/lobby/connect", controller.LobbyWsConnect)
2024-05-03 15:59:20 +00:00
port, ok := os.LookupEnv("PORT")
if !ok {
port = "8080"
}
cors := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3000"},
AllowedMethods: []string{"GET", "DELETE", "POST", "PUT", "OPTIONS"},
AllowedHeaders: []string{"Content-Type", "Origin", "Accept", "Authorization"},
AllowCredentials: true,
})
2024-05-21 14:09:23 +00:00
handler := cors.Handler(mainRouter)
2024-05-03 15:59:20 +00:00
log.Fatal(http.ListenAndServe(":"+port, handler))
}