mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
server init moved to new logger
This commit is contained in:
parent
1f713c11b6
commit
76d77bef9b
3 changed files with 18 additions and 33 deletions
|
@ -1,13 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>TESTDATA Title</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>TESTDATA Heading</h1>
|
|
||||||
<p>TESTDATA paragraph.</p>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -18,10 +18,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/codegangsta/negroni"
|
"github.com/codegangsta/negroni"
|
||||||
|
"github.com/documize/api/wordsmith/log"
|
||||||
"github.com/documize/community/core/api"
|
"github.com/documize/community/core/api"
|
||||||
"github.com/documize/community/core/api/plugins"
|
"github.com/documize/community/core/api/plugins"
|
||||||
"github.com/documize/community/core/database"
|
"github.com/documize/community/core/database"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/web"
|
"github.com/documize/community/core/web"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
@ -29,11 +30,10 @@ import (
|
||||||
var testHost string // used during automated testing
|
var testHost string // used during automated testing
|
||||||
|
|
||||||
// Serve the Documize endpoint.
|
// Serve the Documize endpoint.
|
||||||
func Serve(ready chan struct{}) {
|
func Serve(rt env.Runtime, ready chan struct{}) {
|
||||||
err := plugins.LibSetup()
|
err := plugins.LibSetup()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Terminating before running - invalid plugin.json", err)
|
rt.Log.Error("Terminating before running - invalid plugin.json", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ func Serve(ready chan struct{}) {
|
||||||
|
|
||||||
switch api.Runtime.Flags.SiteMode {
|
switch api.Runtime.Flags.SiteMode {
|
||||||
case web.SiteModeOffline:
|
case web.SiteModeOffline:
|
||||||
log.Info("Serving OFFLINE web app")
|
rt.Log.Info("Serving OFFLINE web app")
|
||||||
case web.SiteModeSetup:
|
case web.SiteModeSetup:
|
||||||
Add(RoutePrefixPrivate, "setup", []string{"POST", "OPTIONS"}, nil, database.Create)
|
Add(RoutePrefixPrivate, "setup", []string{"POST", "OPTIONS"}, nil, database.Create)
|
||||||
log.Info("Serving SETUP web app")
|
rt.Log.Info("Serving SETUP web app")
|
||||||
case web.SiteModeBadDB:
|
case web.SiteModeBadDB:
|
||||||
log.Info("Serving BAD DATABASE web app")
|
rt.Log.Info("Serving BAD DATABASE web app")
|
||||||
default:
|
default:
|
||||||
log.Info("Starting web app")
|
rt.Log.Info("Starting web app")
|
||||||
}
|
}
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
|
@ -79,11 +79,11 @@ func Serve(ready chan struct{}) {
|
||||||
ready <- struct{}{}
|
ready <- struct{}{}
|
||||||
|
|
||||||
if !api.Runtime.Flags.SSLEnabled() {
|
if !api.Runtime.Flags.SSLEnabled() {
|
||||||
log.Info("Starting non-SSL server on " + api.Runtime.Flags.HTTPPort)
|
rt.Log.Info("Starting non-SSL server on " + api.Runtime.Flags.HTTPPort)
|
||||||
n.Run(testHost + ":" + api.Runtime.Flags.HTTPPort)
|
n.Run(testHost + ":" + api.Runtime.Flags.HTTPPort)
|
||||||
} else {
|
} else {
|
||||||
if api.Runtime.Flags.ForceHTTPPort2SSL != "" {
|
if api.Runtime.Flags.ForceHTTPPort2SSL != "" {
|
||||||
log.Info("Starting non-SSL server on " + api.Runtime.Flags.ForceHTTPPort2SSL + " and redirecting to SSL server on " + api.Runtime.Flags.HTTPPort)
|
rt.Log.Info("Starting non-SSL server on " + api.Runtime.Flags.ForceHTTPPort2SSL + " and redirecting to SSL server on " + api.Runtime.Flags.HTTPPort)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := http.ListenAndServe(":"+api.Runtime.Flags.ForceHTTPPort2SSL, http.HandlerFunc(
|
err := http.ListenAndServe(":"+api.Runtime.Flags.ForceHTTPPort2SSL, http.HandlerFunc(
|
||||||
|
@ -93,19 +93,20 @@ func Serve(ready chan struct{}) {
|
||||||
http.Redirect(w, req, "https://"+host, http.StatusMovedPermanently)
|
http.Redirect(w, req, "https://"+host, http.StatusMovedPermanently)
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("ListenAndServe on "+api.Runtime.Flags.ForceHTTPPort2SSL, err)
|
rt.Log.Error("ListenAndServe on "+api.Runtime.Flags.ForceHTTPPort2SSL, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Starting SSL server on " + api.Runtime.Flags.HTTPPort + " with " + api.Runtime.Flags.SSLCertFile + " " + api.Runtime.Flags.SSLKeyFile)
|
rt.Log.Info("Starting SSL server on " + api.Runtime.Flags.HTTPPort + " with " + api.Runtime.Flags.SSLCertFile + " " + api.Runtime.Flags.SSLKeyFile)
|
||||||
|
|
||||||
// TODO: https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/
|
// TODO: https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/
|
||||||
|
|
||||||
server := &http.Server{Addr: ":" + api.Runtime.Flags.HTTPPort, Handler: n /*, TLSConfig: myTLSConfig*/}
|
server := &http.Server{Addr: ":" + api.Runtime.Flags.HTTPPort, Handler: n /*, TLSConfig: myTLSConfig*/}
|
||||||
server.SetKeepAlivesEnabled(true)
|
server.SetKeepAlivesEnabled(true)
|
||||||
|
|
||||||
if err := server.ListenAndServeTLS(api.Runtime.Flags.SSLCertFile, api.Runtime.Flags.SSLKeyFile); err != nil {
|
if err := server.ListenAndServeTLS(api.Runtime.Flags.SSLCertFile, api.Runtime.Flags.SSLKeyFile); err != nil {
|
||||||
log.Error("ListenAndServeTLS on "+api.Runtime.Flags.HTTPPort, err)
|
rt.Log.Error("ListenAndServeTLS on "+api.Runtime.Flags.HTTPPort, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,9 +121,8 @@ func cors(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||||
w.Header().Add("X-Documize-Version", api.Runtime.Product.Version)
|
w.Header().Add("X-Documize-Version", api.Runtime.Product.Version)
|
||||||
w.Header().Add("Cache-Control", "no-cache")
|
w.Header().Add("Cache-Control", "no-cache")
|
||||||
|
|
||||||
if _, err := w.Write([]byte("")); err != nil {
|
w.Write([]byte(""))
|
||||||
log.Error("cors", err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,5 @@ func metrics(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func version(w http.ResponseWriter, r *http.Request) {
|
func version(w http.ResponseWriter, r *http.Request) {
|
||||||
if _, err := w.Write([]byte(api.Runtime.Product.Version)); err != nil {
|
w.Write([]byte(api.Runtime.Product.Version))
|
||||||
log.Error("versionHandler", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,5 +65,5 @@ func main() {
|
||||||
section.Register(rt)
|
section.Register(rt)
|
||||||
|
|
||||||
ready := make(chan struct{}, 1) // channel signals router ready
|
ready := make(chan struct{}, 1) // channel signals router ready
|
||||||
endpoint.Serve(ready)
|
endpoint.Serve(rt, ready)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue