From 04c3f374ccd9f970ecbac1b2d207d84e14a95cea Mon Sep 17 00:00:00 2001 From: Irae Hueck Costa Date: Thu, 22 Feb 2024 19:16:38 +0000 Subject: [PATCH] Changes for hetzner migration --- backend/endpoints/load.js.go | 43 ------------------------------------ backend/lib/app.go | 2 +- static/load.js | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 backend/endpoints/load.js.go create mode 100644 static/load.js diff --git a/backend/endpoints/load.js.go b/backend/endpoints/load.js.go deleted file mode 100644 index 0178c7536..000000000 --- a/backend/endpoints/load.js.go +++ /dev/null @@ -1,43 +0,0 @@ -package endpoints - -import ( - "encoding/json" - "fmt" - "path/filepath" - - "github.com/ihucos/counter.dev/lib" -) - -func init() { - lib.Endpoint(lib.EndpointName(), func(ctx *lib.Ctx) { - // BUG: This related to the static files in the project - // directory. In the deployment static files are taking from - // /state/static. This means NEW components files need to be - // manually touched after a deploy. As a workaround - files1, err := filepath.Glob("./static/components/*.js") - ctx.CatchError(err) - files2, err := filepath.Glob("./static/components/*/*.js") - ctx.CatchError(err) - files3, err := filepath.Glob("./static/components/*/*/*.js") - ctx.CatchError(err) - files := append(append(files1, files2...), files3...) - - serveableFiles := []string{} - for _, file := range files { - serveableFiles = append(serveableFiles, file[6:]) - } - - // this works, but breaks the frontend - you fix it! - for _, file := range serveableFiles { - ctx.W.Header().Add("Link", fmt.Sprintf("<%s>; rel=preload; as=script", file)) - } - - filesJson, err := json.Marshal(serveableFiles) - ctx.CatchError(err) - ctx.Return(fmt.Sprintf(` - %s.sort().map(file => { - let script = document.createElement("script"); - script.src = file; script.async = false; - document.head.appendChild(script)})`, filesJson), 200) - }) -} diff --git a/backend/lib/app.go b/backend/lib/app.go index 8d6523cfb..9089dec55 100644 --- a/backend/lib/app.go +++ b/backend/lib/app.go @@ -132,7 +132,7 @@ func NewApp() *App { } else { prefix = "./static" } - } else if r.Host == "counter.dev" || r.Host == "simple-web-analytics.com" { + } else if r.Host == "counter.dev"|| r.Host == "counter" || r.Host == "simple-web-analytics.com" { prefix = "/state/static/master" } else if r.Host == "www.counter.dev" || r.Host == "www.simple-web-analytics.com" { prefix = "/state/static/master" diff --git a/static/load.js b/static/load.js new file mode 100644 index 000000000..a4e4aa0df --- /dev/null +++ b/static/load.js @@ -0,0 +1,43 @@ +// Add new manually here +[ + "/components/_base.js", + "/components/counter-flash.js", + "/components/counter-trackingcode.js", + "/components/base/editaccount.js", + "/components/base/flash.js", + "/components/base/footer.js", + "/components/base/navbar.js", + "/components/base/pwyw.js", + "/components/dashboard/_base.js", + "/components/dashboard/addbtn.js", + "/components/dashboard/connstatus.js", + "/components/dashboard/daterangeselector.js", + "/components/dashboard/demo-flash.js", + "/components/dashboard/download.js", + "/components/dashboard/dynamics.js", + "/components/dashboard/graph.js", + "/components/dashboard/hour.js", + "/components/dashboard/languages.js", + "/components/dashboard/nodata.js", + "/components/dashboard/number.js", + "/components/dashboard/pages.js", + "/components/dashboard/pie.js", + "/components/dashboard/pwyw.js", + "/components/dashboard/screens.js", + "/components/dashboard/selector.js", + "/components/dashboard/settings.js", + "/components/dashboard/share-account.js", + "/components/dashboard/sources-countries.js", + "/components/dashboard/time-graph.js", + "/components/dashboard/time.js", + "/components/dashboard/visits.js", + "/components/dashboard/week-graph.js", + "/components/dashboard/week.js", + "/components/dashboard/counter/direct.js", + "/components/dashboard/counter/search.js", + "/components/dashboard/counter/social.js", + "/components/dashboard/counter/visitors.js" +].sort().map(file => { + let script = document.createElement("script"); + script.src = file; script.async = false; + document.head.appendChild(script)})