From e83c55257622ae08091a613f69885d7b2e2a70cc Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 1 Jan 2018 14:28:11 -0600 Subject: [PATCH] update compose and remove default admins --- app/main.go | 2 +- app/rest/server.go | 20 +++++++++++++------- docker-compose.yml | 11 +++++++---- remark.rest | 2 -- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/main.go b/app/main.go index be5ef7f5..ee8779bb 100644 --- a/app/main.go +++ b/app/main.go @@ -21,7 +21,7 @@ var opts struct { BoltPath string `long:"bolt" env:"BOLTDB_PATH" default:"/tmp" description:"parent dir for bolt files"` Sites []string `long:"site" env:"SITE" default:"remark" description:"site names" env-delim:","` RemarkURL string `long:"url" env:"REMARK_URL" default:"https://remark42.com" description:"url to remark"` - Admins []string `long:"admin" env:"ADMIN" default:"umputun@gmail.com" description:"admin(s) names" env-delim:","` + Admins []string `long:"admin" env:"ADMIN" description:"admin(s) names" env-delim:","` DevMode bool `long:"dev" env:"DEV" description:"development mode, no auth enforced"` Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` diff --git a/app/rest/server.go b/app/rest/server.go index a3441f4a..fb24d660 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -53,23 +53,27 @@ func (s *Server) Run() { return modes } - s.respCache = cache.New(time.Hour, 5*time.Minute) + if len(s.Admins) > 0 { + log.Printf("[DEBUG] admins %+v", s.Admins) + } + + // cache for responses. Flushes completely on any modification + s.respCache = cache.New(4*time.Hour, 15*time.Minute) router := chi.NewRouter() router.Use(middleware.RealIP, Recoverer) router.Use(middleware.Throttle(1000), middleware.Timeout(60*time.Second)) - router.Use(auth.Auth(s.SessionStore, s.Admins, maybeDevMode(auth.Anonymous))) - router.Use(Limiter(10), AppInfo("remark", s.Version), Ping, Logger(LogAll)) + router.Use(Limiter(10), AppInfo("remark42", s.Version), Ping, Logger(LogAll)) + router.Use(auth.Auth(s.SessionStore, s.Admins, maybeDevMode(auth.Anonymous))) // all request by default allow anonymous access - // If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler - router.Use(context.ClearHandler) + router.Use(context.ClearHandler) // if you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler // auth routes for all providers router.Route("/auth", func(r chi.Router) { r.Mount("/google", s.AuthGoogle.Routes()) r.Mount("/github", s.AuthGithub.Routes()) r.Mount("/facebook", s.AuthFacebook.Routes()) - r.Get("/logout", s.AuthGoogle.LogoutHandler) // shortcut, can be any of providers, does the same + r.Get("/logout", s.AuthGoogle.LogoutHandler) // shortcut, can be any of providers, all logouts do the same }) // api routes @@ -94,6 +98,7 @@ func (s *Server) Run() { }) + // add robots and file server for static content from /web router.Get("/robots.txt", func(w http.ResponseWriter, r *http.Request) { render.PlainText(w, r, "User-agent: *\nDisallow: /auth/\nDisallow: /api/\n") }) @@ -326,7 +331,7 @@ func httpError(w http.ResponseWriter, r *http.Request, code int, err error, deta render.JSON(w, r, JSON{"error": err.Error(), "details": details}) } -// renderJSONWithHTML allows html tags +// renderJSONWithHTML allows html tags and forces charset=utf-8 func renderJSONWithHTML(w http.ResponseWriter, r *http.Request, v interface{}) { buf := &bytes.Buffer{} enc := json.NewEncoder(buf) @@ -342,6 +347,7 @@ func renderJSONWithHTML(w http.ResponseWriter, r *http.Request, v interface{}) { _, _ = w.Write(buf.Bytes()) } +// serves static files from /web func (s *Server) addFileServer(r chi.Router, path string, root http.FileSystem) { fs := http.StripPrefix(path, http.FileServer(root)) diff --git a/docker-compose.yml b/docker-compose.yml index 43fe7f8f..5f9a8616 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,12 +18,15 @@ services: - "8080:8080" environment: - - REMARK_URL=http://remark.umputun.com:8080 - - BOLTDB_FILE=/srv/var/remark.db - - SESSION_STORE=/srv/var + - REMARK_URL=https://demo.remark42.com + - BOLTDB_PATH=/srv/var/db + - BACKUP_PATH=/srv/var/backup + - SESSION_STORE=/srv/var/session - DEV=true # development mode flag. It turns authentication off, be careful! - DEBUG=true volumes: - ./var:/srv/var - - ./web:/srv/web # maps web directory directly and propagate local changes to container without redeploy + - ./web:/srv/web # maps web directory directly to propagate local changes to container without redeploy + + command: /srv/remark server diff --git a/remark.rest b/remark.rest index 2891310e..ba1cb516 100644 --- a/remark.rest +++ b/remark.rest @@ -45,5 +45,3 @@ GET https://demo.remark42.com/api/v1/count?site=remark&url=https://radio-t.com/p ### list commented posts GET https://demo.remark42.com/api/v1/list?site=remark - -###