From 96a844a014549821f8285f412d2f1c3d10e60cf0 Mon Sep 17 00:00:00 2001 From: Geoffroy Arnoud Date: Fri, 17 Jun 2022 11:37:00 +0200 Subject: [PATCH 1/2] dev: Add base.gohtml in assets [#137](https://github.com/statping-ng/statping-ng/issues/137) --- frontend/src/API.js | 2 +- handlers/handlers.go | 29 ++++++++++++++++++++++------- source/source.go | 4 +++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/frontend/src/API.js b/frontend/src/API.js index ffafade6..55e966c8 100644 --- a/frontend/src/API.js +++ b/frontend/src/API.js @@ -8,7 +8,7 @@ const tokenKey = "statping_auth"; class Api { constructor() { this.version = "0.91.0"; - this.commit = "40f31e3110550754a929a9f848c2eefa4df9ae3f"; + this.commit = "b7ecf0c31b0c75c394061d2f6457a925e4440f1e"; } async oauth() { diff --git a/handlers/handlers.go b/handlers/handlers.go index 33346bac..d89d4f30 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -172,18 +172,33 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i if err != nil { log.Errorln(err) } - render, err := source.TmplBox.String(file) - if err != nil { - log.Errorln(err) - } - // render the page requested - if _, err := mainTemplate.Parse(render); err != nil { - log.Errorln(err) + + log.Infoln("Ca commence à être intéressant") + asset := file + if source.UsingAssets(utils.Directory) { + + asset = utils.Directory + "/assets/" + file + log.Infoln(fmt.Sprintf("asset : %s", asset)) + + if _, err := mainTemplate.ParseFiles(asset); err != nil { + log.Errorln(err) + } + } else { + render, err := source.TmplBox.String(asset) + if err != nil { + log.Errorln(err) + } + // render the page requested + if _, err := mainTemplate.Parse(render); err != nil { + log.Errorln(err) + } } + log.Infoln("step 3") // execute the template if err := mainTemplate.Execute(w, data); err != nil { log.Errorln(err) } + log.Infoln("step 4") } func returnJson(d interface{}, w http.ResponseWriter, r *http.Request) { diff --git a/source/source.go b/source/source.go index 20488908..81a7f4ac 100644 --- a/source/source.go +++ b/source/source.go @@ -30,6 +30,7 @@ var ( "scss/mobile.scss", "scss/variables.scss", "robots.txt", + "base.gohtml", } ) @@ -87,6 +88,7 @@ func CompileSASS() error { // UsingAssets returns true if the '/assets' folder is found in the directory func UsingAssets(folder string) bool { + log.Infoln(fmt.Sprintf("using assets? checking %s", folder)) if _, err := os.Stat(folder + "/assets"); err == nil { return true } else { @@ -174,7 +176,7 @@ func DeleteAllAssets(folder string) error { // CopyAllToPublic will copy all the files in a rice box into a local folder func CopyAllToPublic(box *rice.Box) error { exclude := map[string]bool{ - "base.gohtml": true, + // "base.gohtml": true, "index.html": true, } From d0555d792f97fe308a3d44c7844ce85a318ca231 Mon Sep 17 00:00:00 2001 From: Geoffroy Arnoud Date: Wed, 22 Jun 2022 14:32:03 +0200 Subject: [PATCH 2/2] Removed useless logging messages [#137](https://github.com/statping-ng/statping-ng/issues/137) --- handlers/handlers.go | 4 ---- source/source.go | 1 - 2 files changed, 5 deletions(-) diff --git a/handlers/handlers.go b/handlers/handlers.go index d89d4f30..fe8a4ae7 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -173,12 +173,10 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i log.Errorln(err) } - log.Infoln("Ca commence à être intéressant") asset := file if source.UsingAssets(utils.Directory) { asset = utils.Directory + "/assets/" + file - log.Infoln(fmt.Sprintf("asset : %s", asset)) if _, err := mainTemplate.ParseFiles(asset); err != nil { log.Errorln(err) @@ -193,12 +191,10 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i log.Errorln(err) } } - log.Infoln("step 3") // execute the template if err := mainTemplate.Execute(w, data); err != nil { log.Errorln(err) } - log.Infoln("step 4") } func returnJson(d interface{}, w http.ResponseWriter, r *http.Request) { diff --git a/source/source.go b/source/source.go index 81a7f4ac..544ed1a1 100644 --- a/source/source.go +++ b/source/source.go @@ -88,7 +88,6 @@ func CompileSASS() error { // UsingAssets returns true if the '/assets' folder is found in the directory func UsingAssets(folder string) bool { - log.Infoln(fmt.Sprintf("using assets? checking %s", folder)) if _, err := os.Stat(folder + "/assets"); err == nil { return true } else {