2020-07-10 18:07:41 +02:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"forge.cadoles.com/Cadoles/daddy/internal/config"
|
2020-07-13 09:20:14 +02:00
|
|
|
"forge.cadoles.com/Cadoles/daddy/internal/graph"
|
|
|
|
"forge.cadoles.com/Cadoles/daddy/internal/graph/generated"
|
2020-07-10 18:07:41 +02:00
|
|
|
oidc "forge.cadoles.com/wpetit/goweb-oidc"
|
2020-07-13 09:20:14 +02:00
|
|
|
"github.com/99designs/gqlgen/graphql/handler"
|
|
|
|
"github.com/99designs/gqlgen/graphql/playground"
|
2020-07-10 18:07:41 +02:00
|
|
|
|
|
|
|
"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)
|
|
|
|
|
2020-07-13 09:20:14 +02:00
|
|
|
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)
|
2020-07-10 18:07:41 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
notFoundHandler := r.NotFoundHandler()
|
|
|
|
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|