From 629cdc06cdfa9f1683197869a7433cb77c0df743 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 14 Dec 2020 14:28:05 +0100 Subject: [PATCH] More info about api, docs, webapp endpoints --- app/servers.go | 32 ++++++++++++++++++++++++++++---- pkg/api/server/server.go | 7 +++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/servers.go b/app/servers.go index 5deb55906..3026718ff 100644 --- a/app/servers.go +++ b/app/servers.go @@ -11,6 +11,7 @@ import ( systemRest "github.com/cortezaproject/corteza-server/system/rest" "github.com/go-chi/chi" "go.uber.org/zap" + "net/http" "strings" "sync" ) @@ -59,20 +60,43 @@ func (app *CortezaApp) mountHttpRoutes(r chi.Router) { app.WsServer.ApiServerRoutes(r) }) + r.HandleFunc("/docs", func(w http.ResponseWriter, r *http.Request) { + // redirect to endpoint with slash + http.Redirect(w, r, "/"+apiBaseUrl+"/docs/", http.StatusPermanentRedirect) + }) r.HandleFunc("/docs*", server.ServeDocs("/"+apiBaseUrl+"/docs")) }) + + app.Log.Info( + "JSON REST API enabled", + zap.String("baseUrl", app.Opt.HTTPServer.ApiBaseUrl), + ) + + app.Log.Info( + "API docs enabled", + zap.String("baseUrl", app.Opt.HTTPServer.ApiBaseUrl+"/docs"), + ) + } else { + app.Log.Info("JSON REST API disabled") } if app.Opt.HTTPServer.WebappEnabled { - app.Log.Debug( - "serving web applications", - zap.String("baseUrl", webappBaseUrl), + r.Route("/"+webappBaseUrl, webapp.MakeWebappServer(app.Opt.HTTPServer)) + + app.Log.Info( + "client web applications enabled", + zap.String("baseUrl", app.Opt.HTTPServer.WebappBaseUrl), zap.String("baseDir", app.Opt.HTTPServer.WebappBaseDir), ) - r.Route("/"+webappBaseUrl, webapp.MakeWebappServer(app.Opt.HTTPServer)) + } else { + app.Log.Info("client web applications disabled") } if app.Opt.Federation.Enabled { r.Route("/federation", federationRest.MountRoutes) + } else { + app.Log.Info( + "federation API disabled", + ) } } diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go index d9f5c52ee..26571a621 100644 --- a/pkg/api/server/server.go +++ b/pkg/api/server/server.go @@ -41,14 +41,13 @@ func (s *server) MountRoutes(mm ...func(chi.Router)) { func (s server) Serve(ctx context.Context) { s.log.Info( - "Starting HTTP server with REST API", + "starting HTTP server", zap.String("address", s.httpOpt.Addr), - zap.String("baseUrl", s.httpOpt.ApiBaseUrl), ) listener, err := net.Listen("tcp", s.httpOpt.Addr) if err != nil { - s.log.Error("Can not start server", zap.Error(err)) + s.log.Error("can not start server", zap.Error(err)) return } @@ -100,7 +99,7 @@ func (s server) Serve(ctx context.Context) { } } - s.log.Info("Server stopped", zap.Error(err)) + s.log.Info("HTTP server stopped", zap.Error(err)) } func (s server) bindMiscRoutes(router chi.Router) {