Skip to content

Commit

Permalink
fix: return absolute url for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jul 8, 2022
1 parent 4bdd291 commit a3f4cb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/pkg/web/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/pkg/web/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a3f4cb5

Please sign in to comment.