Skip to content

Commit

Permalink
Added: Errors while starting the HTTP/HTTPS server are now logged.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabukky committed May 12, 2015
1 parent 7bf7027 commit 48983c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
27 changes: 14 additions & 13 deletions filenames/filenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -77,7 +78,7 @@ func determineContentPath() string {
} else {
contentPath = determineExecutablePath()
}
return filepath.Join(contentPath, "content")
return contentPath
}

func determineExecutablePath() string {
Expand Down
29 changes: 24 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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)
}
}
}

0 comments on commit 48983c9

Please sign in to comment.