@@ -69,10 +69,18 @@ import (
69
69
persesMiddleware "github.com/perses/common/echo/middleware"
70
70
)
71
71
72
- var hidePort bool
72
+ var (
73
+ hidePort bool
74
+ // https cert for server
75
+ cert string
76
+ // https key for server
77
+ key string
78
+ )
73
79
74
80
func init () {
75
81
flag .BoolVar (& hidePort , "web.hide-port" , false , "If true, it won't be print on stdout the port listened to receive the HTTP request" )
82
+ flag .StringVar (& cert , "web.tls-cert-file" , "" , "The path to the cert to use for the HTTPS server" )
83
+ flag .StringVar (& key , "web.tls-key-file" , "" , "The path to the key to use for the HTTPS server" )
76
84
}
77
85
78
86
type Register interface {
@@ -212,6 +220,8 @@ func (b *Builder) build() (*server, error) {
212
220
addr : b .addr ,
213
221
apis : b .apis ,
214
222
e : e ,
223
+ cert : cert ,
224
+ key : key ,
215
225
mdws : b .mdws ,
216
226
preMDWs : b .preMDWs ,
217
227
shutdownTimeout : 30 * time .Second ,
@@ -224,6 +234,8 @@ type server struct {
224
234
addr string
225
235
apis []Register
226
236
e * echo.Echo
237
+ cert string
238
+ key string
227
239
mdws []echo.MiddlewareFunc
228
240
preMDWs []echo.MiddlewareFunc
229
241
shutdownTimeout time.Duration
@@ -257,9 +269,16 @@ func (s *server) Execute(ctx context.Context, cancelFunc context.CancelFunc) err
257
269
serverCtx , serverCancelFunc := context .WithCancel (ctx )
258
270
go func () {
259
271
defer serverCancelFunc ()
260
- if err := s .e .Start (s .addr ); err != nil {
261
- logrus .WithError (err ).Info ("http server stopped" )
272
+ if s .cert != "" && s .key != "" {
273
+ if err := s .e .StartTLS (s .addr , s .cert , s .key ); err != nil {
274
+ logrus .WithError (err ).Info ("http server stopped" )
275
+ }
276
+ } else {
277
+ if err := s .e .Start (s .addr ); err != nil {
278
+ logrus .WithError (err ).Info ("http server stopped" )
279
+ }
262
280
}
281
+
263
282
logrus .Debug ("go routine running the http server has been stopped." )
264
283
}()
265
284
// Wait for the end of the task or cancellation
0 commit comments