William Petit
3fd8bf7e69
- Sauvegarde de l'adresse courriel de l'utilisateur en session - Implémentation d'une première Query GraphQL pour récupérer le profil de l'utilisateur connecté - Utilisation de la pattern CQRS pour les commandes/requêtes sur la base de données
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
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
|
|
}
|