From a3f4cb5ed0a4ee2d726705fc426636364aac17a1 Mon Sep 17 00:00:00 2001 From: goenning Date: Fri, 8 Jul 2022 17:47:01 +0100 Subject: [PATCH] fix: return absolute url for assets --- app/pkg/web/context.go | 3 ++- app/pkg/web/context_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go index d60f8e46b..e566a03f6 100644 --- a/app/pkg/web/context.go +++ b/app/pkg/web/context.go @@ -550,6 +550,7 @@ func TenantBaseURL(ctx context.Context, tenant *entity.Tenant) string { } // AssetsURL return the full URL to a tenant-specific static asset +// It should always return an absolute URL func AssetsURL(ctx context.Context, path string, a ...any) string { request := ctx.Value(app.RequestCtxKey).(Request) path = fmt.Sprintf(path, a...) @@ -558,7 +559,7 @@ func AssetsURL(ctx context.Context, path string, a ...any) string { if env.Config.CDN.Host != "" { return request.URL.Scheme + "://" + env.Config.CDN.Host + path } - return path + return BaseURL(ctx) + path } tenant, hasTenant := ctx.Value(app.TenantCtxKey).(*entity.Tenant) diff --git a/app/pkg/web/context_test.go b/app/pkg/web/context_test.go index 151ec12a6..8bf097095 100644 --- a/app/pkg/web/context_test.go +++ b/app/pkg/web/context_test.go @@ -128,8 +128,8 @@ func TestAssetsURL_SingleHostMode(t *testing.T) { Subdomain: "theavengers", }) - Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("/assets/main.js") - Expect(web.AssetsURL(ctx, "/assets/main.css")).Equals("/assets/main.css") + Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("https://test.fider.io:3000/assets/main.js") + Expect(web.AssetsURL(ctx, "/assets/main.css")).Equals("https://test.fider.io:3000/assets/main.css") env.Config.CDN.Host = "fidercdn.com" Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("http://fidercdn.com/assets/main.js")