Skip to content

Commit 450a40f

Browse files
authored
Fix Community Server open connections (#223)
1 parent e641d35 commit 450a40f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

services/community/api/router/routes.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"net/http"
2020
"os"
21+
"time"
2122

2223
"crapi.proj/goservice/api/config"
2324
"crapi.proj/goservice/api/controllers"
@@ -59,6 +60,12 @@ func (server *Server) InitializeRoutes() *mux.Router {
5960

6061
func (server *Server) Run(addr string) {
6162
fmt.Println("Listening to port " + os.Getenv("SERVER_PORT"))
63+
srv := &http.Server{
64+
Addr: addr,
65+
Handler: server.Router,
66+
ReadTimeout: 30 * time.Second,
67+
WriteTimeout: 30 * time.Second,
68+
}
6269
if utils.IsTLSEnabled() {
6370
// Check if env variable TLS_CERTIFICATE is set then use it as certificate else default to certs/server.crt
6471
certificate, is_cert := os.LookupEnv("TLS_CERTIFICATE")
@@ -70,12 +77,12 @@ func (server *Server) Run(addr string) {
7077
if !is_key || key == "" {
7178
key = "certs/server.key"
7279
}
73-
err := http.ListenAndServeTLS(addr, certificate, key, server.Router)
80+
err := srv.ListenAndServeTLS(certificate, key)
7481
if err != nil {
7582
fmt.Println(err)
7683
}
7784
} else {
78-
err := http.ListenAndServe(addr, server.Router)
85+
err := srv.ListenAndServe()
7986
if err != nil {
8087
fmt.Println(err)
8188
}

0 commit comments

Comments
 (0)