Fixed bug with server
@@ -40,40 +40,41 @@ func RunServer(cmd *cobra.Command, args []string) {
dsnURL, err := url.Parse(globalConfig.Database.DSN)
switch dsnURL.Scheme {
case "mongodb":
- log.WithField("dsn", globalConfig.Database.DSN).Debug("Trying to connect to DB")
+ log.Debug("MongoDB configuration chosen")
+
+ log.WithField("dsn", globalConfig.Database.DSN).Debug("Trying to connect to MongoDB...")
session, err := mgo.Dial(globalConfig.Database.DSN)
if err != nil {
log.Panic(err)
}
-
defer session.Close()
- log.Debug("Connected to mongodb")
+ log.Debug("Connected to MongoDB")
session.SetMode(mgo.Monotonic, true)
- log.Debug("Loading API definitions from Mongo DB")
repo, err = api.NewMongoAppRepository(session)
if err != nil {
log.Panic(err)
}
- // create the proxy
- log.Debug("Loading OAuth servers definitions from Mongo DB")
oAuthServersRepo, err = oauth.NewMongoRepository(session)
if err != nil {
log.Panic(err)
}
case "file":
+ log.Debug("File system based configuration chosen")
var apiPath = dsnURL.Path + "/apis"
var authPath = dsnURL.Path + "/auth"
- log.WithField("path", apiPath).Debug("Loading API definitions from file system")
+ log.WithFields(log.Fields{
+ "api_path": apiPath,
+ "auth_path": authPath,
+ }).Debug("Trying to load configuration files")
repo, err = api.NewFileSystemRepository(apiPath)
if err != nil {
log.Panic(err)
}
- log.WithField("path", authPath).Debug("Loading OAuth servers definitions from file system")
oAuthServersRepo, err = oauth.NewFileSystemRepository(authPath)
if err != nil {
log.Panic(err)
@@ -98,7 +99,6 @@ func RunServer(cmd *cobra.Command, args []string) {
wp.Provide(version)
r := createRouter()
-
loader.Load(loader.Params{
Router: r,
Storage: storage,
@@ -118,24 +118,25 @@ func RunServer(cmd *cobra.Command, args []string) {
func listenAndServe(handler http.Handler) error {
address := fmt.Sprintf(":%v", globalConfig.Port)
+ server = &http.Server{Addr: address, Handler: handler}
log.Info("Janus started")
-
if globalConfig.TLS.IsHTTPS() {
- addressTLS := fmt.Sprintf(":%v", globalConfig.TLS.Port)
+ server.Addr = fmt.Sprintf(":%v", globalConfig.TLS.Port)
+
if globalConfig.TLS.Redirect {
go func() {
- log.WithField("address", address).Info("Listening HTTP")
+ log.WithField("address", address).Info("Listening HTTP redirects to HTTPS")
log.Fatal(http.ListenAndServe(address, web.RedirectHTTPS(globalConfig.TLS.Port)))
}()
}
- log.WithField("address", addressTLS).Info("Listening HTTPS")
- return http.ListenAndServeTLS(addressTLS, globalConfig.TLS.CertFile, globalConfig.TLS.KeyFile, handler)
+ log.WithField("address", server.Addr).Info("Listening HTTPS")
+ return server.ListenAndServeTLS(globalConfig.TLS.CertFile, globalConfig.TLS.KeyFile)
}
log.WithField("address", address).Info("Certificate and certificate key were not found, defaulting to HTTP")
- return http.ListenAndServe(address, handler)
+ return server.ListenAndServe()
}
func createRouter() router.Router {
