Skip to content

Commit

Permalink
If no route return index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Mar 9, 2023
1 parent e2f5321 commit 535198c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 535198c

Please sign in to comment.