service: add react web app serving option

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2022-06-03 13:12:19 +02:00
parent 9174446b2c
commit ec06b7c4a2
3 changed files with 34 additions and 1 deletions

View File

@ -133,6 +133,9 @@ func newService(opts ...Option) (*service, error) {
if err := s.gateway(s.opts.gatewayOpts...); err != nil {
return nil, err
}
if err := s.reactApp(); err != nil {
return nil, err
}
// we do not configure grpc web here as the grpc handlers are not yet registered
return s, nil
}
@ -203,7 +206,7 @@ func (s *service) run() error {
hServer := &http.Server{
Handler: alice.New(s.opts.middlewares...).Then(cors.New(s.opts.cors).Handler(s.opts.mux)),
}
if s.opts.Gateway() || s.opts.grpcWeb {
if s.opts.Gateway() || s.opts.grpcWeb || s.opts.hasReactUI {
go func() {
errs <- hServer.Serve(hList)
hServer.Shutdown(s.opts.ctx)