Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: don't cache the assets base url (#669)

Guilherme Oenning0290a8468a9a
diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.go
index 2195bb11c..990c8a413 100644
--- a/app/pkg/web/renderer.go
+++ b/app/pkg/web/renderer.go
@@ -66,7 +66,7 @@ func (r *Renderer) add(name string) *template.Template {
return tpl
}
-func (r *Renderer) loadAssets(ctx *Context) error {
+func (r *Renderer) loadAssets() error {
r.mutex.Lock()
defer r.mutex.Unlock()
@@ -74,8 +74,6 @@ func (r *Renderer) loadAssets(ctx *Context) error {
return nil
}
- ctx.logger.Debug("Loading client assets")
-
type assetsFile struct {
Entrypoints struct {
Main struct {
@@ -113,7 +111,7 @@ func (r *Renderer) loadAssets(ctx *Context) error {
continue
}
- assetURL := ctx.GlobalAssetsURL("/assets/" + asset)
+ assetURL := "/assets/" + asset
if strings.HasSuffix(asset, ".css") {
r.assets.CSS = append(r.assets.CSS, assetURL)
} else if strings.HasSuffix(asset, ".js") {
@@ -129,7 +127,7 @@ func (r *Renderer) Render(w io.Writer, name string, props Props, ctx *Context) {
var err error
if r.assets == nil || env.IsDevelopment() {
- err := r.loadAssets(ctx)
+ err := r.loadAssets()
if err != nil && !env.IsTest() {
panic(err)
}
diff --git a/app/pkg/web/testdata/basic.html b/app/pkg/web/testdata/basic.html
index 6148c34cd..97f3ab440 100755
--- a/app/pkg/web/testdata/basic.html
+++ b/app/pkg/web/testdata/basic.html
@@ -34,7 +34,7 @@
<script id="server-data" type="application/json">
- {"__assets":{"CSS":["https://demo.test.fider.io:3000/assets/css/file1.css"],"JS":["https://demo.test.fider.io:3000/assets/js/file1.js","https://demo.test.fider.io:3000/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"Fider"}
+ {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"Fider"}
</script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch" crossorigin="anonymous"></script>
diff --git a/app/pkg/web/testdata/props.html b/app/pkg/web/testdata/props.html
index dba290fd5..9605892c5 100755
--- a/app/pkg/web/testdata/props.html
+++ b/app/pkg/web/testdata/props.html
@@ -34,7 +34,7 @@
<script id="server-data" type="application/json">
- {"__assets":{"CSS":["https://demo.test.fider.io:3000/assets/css/file1.css"],"JS":["https://demo.test.fider.io:3000/assets/js/file1.js","https://demo.test.fider.io:3000/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":{"array":["1","2"],"number":2,"object":{"key1":"value1","key2":"value2"}},"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider"}
+ {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":{"array":["1","2"],"number":2,"object":{"key1":"value1","key2":"value2"}},"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider"}
</script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch" crossorigin="anonymous"></script>
diff --git a/app/pkg/web/testdata/tenant.html b/app/pkg/web/testdata/tenant.html
index cdd95018e..4759eddea 100755
--- a/app/pkg/web/testdata/tenant.html
+++ b/app/pkg/web/testdata/tenant.html
@@ -36,7 +36,7 @@
<script id="server-data" type="application/json">
- {"__assets":{"CSS":["https://demo.test.fider.io:3000/assets/css/file1.css"],"JS":["https://demo.test.fider.io:3000/assets/js/file1.js","https://demo.test.fider.io:3000/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":{"id":0,"name":"Game of Thrones","subdomain":"","invitation":"","welcomeMessage":"","cname":"","isPrivate":false,"logoID":0},"__title":"Game of Thrones"}
+ {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":{"id":0,"name":"Game of Thrones","subdomain":"","invitation":"","welcomeMessage":"","cname":"","isPrivate":false,"logoID":0},"__title":"Game of Thrones"}
</script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch" crossorigin="anonymous"></script>
diff --git a/app/pkg/web/testdata/user.html b/app/pkg/web/testdata/user.html
index 307365734..a21abedd6 100755
--- a/app/pkg/web/testdata/user.html
+++ b/app/pkg/web/testdata/user.html
@@ -34,7 +34,7 @@
<script id="server-data" type="application/json">
- {"__assets":{"CSS":["https://demo.test.fider.io:3000/assets/css/file1.css"],"JS":["https://demo.test.fider.io:3000/assets/js/file1.js","https://demo.test.fider.io:3000/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider","__user":{"email":"[email protected]","id":0,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}
+ {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon.ico","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider","__user":{"email":"[email protected]","id":0,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}
</script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch" crossorigin="anonymous"></script>
diff --git a/views/base.html b/views/base.html
index e5af1ae8f..5d73e43d6 100644
--- a/views/base.html
+++ b/views/base.html
@@ -7,7 +7,7 @@
<link rel="icon" type="image/x-icon" href="{{ .__favicon }}">
{{ if .__assets }}
{{range .__assets.CSS}}
- <link rel="stylesheet" href="{{ . }}" />
+ <link rel="stylesheet" href="{{ $.__settings.globalAssetsURL }}{{ . }}" />
{{end}}
{{end}}
<title>{{ .__title }}</title>
diff --git a/views/index.html b/views/index.html
index eb7fd4ead..1320e8a13 100644
--- a/views/index.html
+++ b/views/index.html
@@ -7,7 +7,7 @@
{{define "end-of-body"}}
{{ if .__assets }}
{{range .__assets.JS}}
- <script src="{{ . }}" crossorigin="anonymous"></script>
+ <script src="{{ $.__settings.globalAssetsURL }}{{ . }}" crossorigin="anonymous"></script>
{{end}}
{{end}}
{{end}}
\ No newline at end of file