From 535198c1874be0df7eb266c413ee0d192d18f8b8 Mon Sep 17 00:00:00 2001 From: David Viejo Date: Thu, 9 Mar 2023 13:15:44 +0100 Subject: [PATCH] If no route return index.html --- api/cmd/serve/serve.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/cmd/serve/serve.go b/api/cmd/serve/serve.go index fdfc267..4d47296 100644 --- a/api/cmd/serve/serve.go +++ b/api/cmd/serve/serve.go @@ -248,6 +248,7 @@ func (s serveCmd) run() error { fileSystem := ui.NewFileSystemUI(s.views, "web") serverMux.Use(static.Serve("/", fileSystem)) + serverMux.NoRoute(ReturnPublic()) graphqlHandler := gin.HandlerFunc(func(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Origin", "*") @@ -300,6 +301,17 @@ func (s serveCmd) run() error { return http.ListenAndServe(s.address, httpHandler) } +func ReturnPublic() gin.HandlerFunc { + return func(context *gin.Context) { + method := context.Request.Method + if method == "GET" { + context.File("/Users/davidviejo/projects/kfs/hlf-operator-ui/ui/dist") + } else { + context.Next() + } + } +} + // Defining the Playground handler func playgroundHandler() gin.HandlerFunc { h := playground.Handler("GraphQL", "/graphql")