Skip to content

Commit

Permalink
dev: add ui support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Nov 22, 2018
1 parent 4e1e670 commit 1f435dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cmd/api/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/fagongzi/gateway/pkg/util"
"github.com/fagongzi/grpcx"
"github.com/fagongzi/log"
"github.com/labstack/echo"
"google.golang.org/grpc"
)

Expand All @@ -28,6 +29,8 @@ var (
servicePrefix = flag.String("service-prefix", "/services", "The prefix for service name.")
publishLease = flag.Int64("publish-lease", 10, "Publish service lease seconds")
publishTimeout = flag.Int("publish-timeout", 30, "Publish service timeout seconds")
ui = flag.String("ui", "/app/gateway-ui", "The gateway ui dist dir.")
uiPrefix = flag.String("ui-prefix", "/ui", "The gateway ui prefix path.")
version = flag.Bool("version", false, "Show version info")
)

Expand Down Expand Up @@ -64,7 +67,9 @@ func main() {
}

if *addrHTTP != "" {
opts = append(opts, grpcx.WithHTTPServer(*addrHTTP, service.InitHTTPRouter))
opts = append(opts, grpcx.WithHTTPServer(*addrHTTP, func(server *echo.Echo) {
service.InitHTTPRouter(server, *ui, *uiPrefix)
}))
}

s := grpcx.NewGRPCServer(*addr, func(svr *grpc.Server) []grpcx.Service {
Expand Down
3 changes: 2 additions & 1 deletion pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const (
)

// InitHTTPRouter init http router
func InitHTTPRouter(server *echo.Echo) {
func InitHTTPRouter(server *echo.Echo, ui, uiPrefix string) {
initClusterRouter(server)
initServerRouter(server)
initBindRouter(server)
initRoutingRouter(server)
initAPIRouter(server)
initStatic(server, ui, uiPrefix)
}

type limitQuery struct {
Expand Down
9 changes: 9 additions & 0 deletions pkg/service/http_static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package service

import (
"github.com/labstack/echo"
)

func initStatic(server *echo.Echo, ui, uiPrefix string) {
server.Static(uiPrefix, ui)
}

0 comments on commit 1f435dc

Please sign in to comment.