Skip to content

Commit a3f4cb5

Browse files
committed
fix: return absolute url for assets
1 parent 4bdd291 commit a3f4cb5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

app/pkg/web/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func TenantBaseURL(ctx context.Context, tenant *entity.Tenant) string {
550550
}
551551

552552
// AssetsURL return the full URL to a tenant-specific static asset
553+
// It should always return an absolute URL
553554
func AssetsURL(ctx context.Context, path string, a ...any) string {
554555
request := ctx.Value(app.RequestCtxKey).(Request)
555556
path = fmt.Sprintf(path, a...)
@@ -558,7 +559,7 @@ func AssetsURL(ctx context.Context, path string, a ...any) string {
558559
if env.Config.CDN.Host != "" {
559560
return request.URL.Scheme + "://" + env.Config.CDN.Host + path
560561
}
561-
return path
562+
return BaseURL(ctx) + path
562563
}
563564

564565
tenant, hasTenant := ctx.Value(app.TenantCtxKey).(*entity.Tenant)

app/pkg/web/context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func TestAssetsURL_SingleHostMode(t *testing.T) {
128128
Subdomain: "theavengers",
129129
})
130130

131-
Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("/assets/main.js")
132-
Expect(web.AssetsURL(ctx, "/assets/main.css")).Equals("/assets/main.css")
131+
Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("https://test.fider.io:3000/assets/main.js")
132+
Expect(web.AssetsURL(ctx, "/assets/main.css")).Equals("https://test.fider.io:3000/assets/main.css")
133133

134134
env.Config.CDN.Host = "fidercdn.com"
135135
Expect(web.AssetsURL(ctx, "/assets/main.js")).Equals("http://fidercdn.com/assets/main.js")

0 commit comments

Comments
 (0)