package route import ( "forge.cadoles.com/Cadoles/daddy/internal/config" "forge.cadoles.com/Cadoles/daddy/internal/graph" "forge.cadoles.com/Cadoles/daddy/internal/graph/generated" "forge.cadoles.com/Cadoles/daddy/internal/session" oidc "forge.cadoles.com/wpetit/goweb-oidc" "github.com/99designs/gqlgen/graphql/handler" "github.com/99designs/gqlgen/graphql/playground" "github.com/go-chi/chi" "gitlab.com/wpetit/goweb/static" ) func Mount(r *chi.Mux, config *config.Config) error { r.With(oidc.HandleCallback).Get("/oauth2/callback", handleLoginCallback) r.Get("/logout", handleLogout) r.Get("/login", handleLogin) r.Get("/logout/redirect", handleLogoutRedirect) r.Route("/api", func(r chi.Router) { r.Use(oidc.Middleware) r.Use(session.UserEmailMiddleware) gql := handler.NewDefaultServer( generated.NewExecutableSchema(generated.Config{ Resolvers: &graph.Resolver{}, }), ) if config.Debug { r.Get("/v1/graphql", playground.Handler("GraphQL playground", "/api/v1/graphql")) } r.Post("/v1/graphql", gql.ServeHTTP) }) notFoundHandler := r.NotFoundHandler() r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler)) return nil }