From 48983c9d72eb7d45487c697d202997c687a14c7b Mon Sep 17 00:00:00 2001 From: Kai H Date: Tue, 12 May 2015 14:25:54 +0200 Subject: [PATCH] Added: Errors while starting the HTTP/HTTPS server are now logged. --- filenames/filenames.go | 27 ++++++++++++++------------- main.go | 29 ++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/filenames/filenames.go b/filenames/filenames.go index 3aeaea9a..8bf8e001 100644 --- a/filenames/filenames.go +++ b/filenames/filenames.go @@ -12,22 +12,23 @@ var ( // Determine the path the Journey executable is in - needed to load relative assets ExecutablePath = determineExecutablePath() - // Determine the path the the content folder - ContentPath = determineContentPath() + // Determine the path the the assets folder (default: Journey root folder) + AssetPath = determineContentPath() // For assets that are created, changed, our user-provided while running journey - ConfigFilename = filepath.Join(ExecutablePath, "config.json") - DatabaseFilepath = filepath.Join(ContentPath, "data") - DatabaseFilename = filepath.Join(ContentPath, "data", "journey.db") - ThemesFilepath = filepath.Join(ContentPath, "themes") - ImagesFilepath = filepath.Join(ContentPath, "images") - PluginsFilepath = filepath.Join(ContentPath, "plugins") - PagesFilepath = filepath.Join(ContentPath, "pages") + ConfigFilename = filepath.Join(AssetPath, "config.json") + ContentFilepath = filepath.Join(AssetPath, "content") + DatabaseFilepath = filepath.Join(ContentFilepath, "data") + DatabaseFilename = filepath.Join(ContentFilepath, "data", "journey.db") + ThemesFilepath = filepath.Join(ContentFilepath, "themes") + ImagesFilepath = filepath.Join(ContentFilepath, "images") + PluginsFilepath = filepath.Join(ContentFilepath, "plugins") + PagesFilepath = filepath.Join(ContentFilepath, "pages") // For https - HttpsFilepath = filepath.Join(ContentPath, "https") - HttpsCertFilename = filepath.Join(ContentPath, "https", "cert.pem") - HttpsKeyFilename = filepath.Join(ContentPath, "https", "key.pem") + HttpsFilepath = filepath.Join(ContentFilepath, "https") + HttpsCertFilename = filepath.Join(ContentFilepath, "https", "cert.pem") + HttpsKeyFilename = filepath.Join(ContentFilepath, "https", "key.pem") //For built-in files (e.g. the admin interface) AdminFilepath = filepath.Join(ExecutablePath, "built-in", "admin") @@ -77,7 +78,7 @@ func determineContentPath() string { } else { contentPath = determineExecutablePath() } - return filepath.Join(contentPath, "content") + return contentPath } func determineExecutablePath() string { diff --git a/main.go b/main.go index d2bee16a..ad4539c6 100644 --- a/main.go +++ b/main.go @@ -116,10 +116,18 @@ func main() { server.InitializeAdmin(httpsRouter) // Start https server log.Println("Starting https server on port " + httpsPort + "...") - go http.ListenAndServeTLS(httpsPort, filenames.HttpsCertFilename, filenames.HttpsKeyFilename, httpsRouter) + go func() { + err := http.ListenAndServeTLS(httpsPort, filenames.HttpsCertFilename, filenames.HttpsKeyFilename, httpsRouter) + if err != nil { + log.Fatal("Error: Couldn't start the HTTPS server:", err) + } + }() // Start http server log.Println("Starting http server on port " + httpPort + "...") - http.ListenAndServe(httpPort, httpRouter) + err := http.ListenAndServe(httpPort, httpRouter) + if err != nil { + log.Fatal("Error: Couldn't start the HTTP server:", err) + } case "All": checkHttpsCertificates() httpsRouter := httptreemux.New() @@ -134,10 +142,18 @@ func main() { httpRouter.GET("/*path", httpsRedirect) // Start https server log.Println("Starting https server on port " + httpsPort + "...") - go http.ListenAndServeTLS(httpsPort, filenames.HttpsCertFilename, filenames.HttpsKeyFilename, httpsRouter) + go func() { + err := http.ListenAndServeTLS(httpsPort, filenames.HttpsCertFilename, filenames.HttpsKeyFilename, httpsRouter) + if err != nil { + log.Fatal("Error: Couldn't start the HTTPS server:", err) + } + }() // Start http server log.Println("Starting http server on port " + httpPort + "...") - http.ListenAndServe(httpPort, httpRouter) + err := http.ListenAndServe(httpPort, httpRouter) + if err != nil { + log.Fatal("Error: Couldn't start the HTTP server:", err) + } default: // This is configuration.HttpsUsage == "None" httpRouter := httptreemux.New() // Blog and pages as http @@ -148,6 +164,9 @@ func main() { // Start http server log.Println("Starting server without HTTPS support. Please enable HTTPS in " + filenames.ConfigFilename + " to improve security.") log.Println("Starting http server on port " + httpPort + "...") - http.ListenAndServe(httpPort, httpRouter) + err := http.ListenAndServe(httpPort, httpRouter) + if err != nil { + log.Fatal("Error: Couldn't start the HTTP server:", err) + } } }