Open platform to collect and prioritize feedback
enhancement: centralize static content under /static route (#959)
Guilherme Oenning7a5d10603257
diff --git a/app/cmd/routes.go b/app/cmd/routes.goindex 9b3585d80..eb8b3593c 100644--- a/app/cmd/routes.go+++ b/app/cmd/routes.go@@ -33,7 +33,7 @@ func routes(r *web.Engine) *web.Engine {{assets.Use(middlewares.CORS())assets.Use(middlewares.ClientCache(365 * 24 * time.Hour))- assets.Get("/favicon", handlers.Favicon())+ assets.Get("/static/favicon", handlers.Favicon())assets.Static("/assets/*filepath", "dist")}@@ -65,13 +65,13 @@ func routes(r *web.Engine) *web.Engine {tenantAssets := r.Group(){tenantAssets.Use(middlewares.ClientCache(5 * 24 * time.Hour))- tenantAssets.Get("/avatars/letter/:id/:name", handlers.LetterAvatar())- tenantAssets.Get("/avatars/gravatar/:id/:name", handlers.Gravatar())+ tenantAssets.Get("/static/avatars/letter/:id/:name", handlers.LetterAvatar())+ tenantAssets.Get("/static/avatars/gravatar/:id/:name", handlers.Gravatar())tenantAssets.Use(middlewares.ClientCache(30 * 24 * time.Hour))- tenantAssets.Get("/favicon/*bkey", handlers.Favicon())- tenantAssets.Get("/images/*bkey", handlers.ViewUploadedImage())- tenantAssets.Get("/custom/:md5.css", func(c *web.Context) error {+ tenantAssets.Get("/static/favicon/*bkey", handlers.Favicon())+ tenantAssets.Get("/static/images/*bkey", handlers.ViewUploadedImage())+ tenantAssets.Get("/static/custom/:md5.css", func(c *web.Context) error {return c.Blob(http.StatusOK, "text/css", []byte(c.Tenant().CustomCSS))})}diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex 7cb25114f..186cecb30 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -568,7 +568,7 @@ func AssetsURL(ctx context.Context, path string, a ...interface{}) string {func LogoURL(ctx context.Context) string {tenant, hasTenant := ctx.Value(app.TenantCtxKey).(*entity.Tenant)if hasTenant && tenant.LogoBlobKey != "" {- return AssetsURL(ctx, "/images/%s?size=200", tenant.LogoBlobKey)+ return AssetsURL(ctx, "/static/images/%s?size=200", tenant.LogoBlobKey)}return "https://getfider.com/images/logo-100x100.png"}diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.goindex 6e4140149..b4a651281 100644--- a/app/pkg/web/renderer.go+++ b/app/pkg/web/renderer.go@@ -190,9 +190,9 @@ func (r *Renderer) Render(w io.Writer, statusCode int, templateName string, propprivate["logo"] = LogoURL(ctx)if tenant == nil || tenant.LogoBlobKey == "" {- private["favicon"] = AssetsURL(ctx, "/favicon")+ private["favicon"] = AssetsURL(ctx, "/static/favicon")} else {- private["favicon"] = AssetsURL(ctx, "/favicon/%s", tenant.LogoBlobKey)+ private["favicon"] = AssetsURL(ctx, "/static/favicon/%s", tenant.LogoBlobKey)}private["currentURL"] = ctx.Request.URL.String()@@ -221,7 +221,7 @@ func (r *Renderer) Render(w io.Writer, statusCode int, templateName string, prop"domain": env.MultiTenantDomain(),"hasLegal": env.HasLegal(),"baseURL": ctx.BaseURL(),- "assetsURL": AssetsURL(ctx, ""),+ "assetsURL": AssetsURL(ctx, ""),"oauth": oauthProviders.Result,}diff --git a/app/pkg/web/renderer_test.go b/app/pkg/web/renderer_test.goindex df6a5ec25..56bbc6d12 100644--- a/app/pkg/web/renderer_test.go+++ b/app/pkg/web/renderer_test.go@@ -151,7 +151,7 @@ func TestRenderer_AuthenticatedUser(t *testing.T) {Status: enum.UserActive,Role: enum.RoleAdministrator,AvatarType: enum.AvatarTypeGravatar,- AvatarURL: "https://demo.test.fider.io:3000/avatars/gravatar/5/Jon%20Snow",+ AvatarURL: "https://demo.test.fider.io:3000/static/avatars/gravatar/5/Jon%20Snow",})renderer := web.NewRenderer()renderer.Render(buf, http.StatusOK, "index.html", web.Props{diff --git a/app/pkg/web/ssl.go b/app/pkg/web/ssl.goindex 418913a38..228cb53ea 100644--- a/app/pkg/web/ssl.go+++ b/app/pkg/web/ssl.go@@ -72,13 +72,8 @@ func (m *CertificateManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Cereturn &m.cert, nil}- if env.IsSingleHostMode() {+ if env.IsSingleHostMode() || m.leaf.VerifyHostname(serverName) == nil {return &m.cert, nil- } else if strings.HasSuffix(serverName, env.MultiTenantDomain()) {- if m.leaf.VerifyHostname(serverName) == nil {- return &m.cert, nil- }- return nil, errors.New(`ssl: invalid server name "%s"`, serverName)}}diff --git a/app/pkg/web/ssl_test.go b/app/pkg/web/ssl_test.goindex 6704d0278..019d8449c 100644--- a/app/pkg/web/ssl_test.go+++ b/app/pkg/web/ssl_test.go@@ -16,16 +16,13 @@ func Test_GetCertificate(t *testing.T) {mode stringcert stringserverName string- valid bool}{- {"multi", "all-test-fider-io", "", true},- {"multi", "all-test-fider-io", "fider", true},- {"multi", "all-test-fider-io", "feedback.test.fider.io", true},- {"multi", "all-test-fider-io", "FEEDBACK.test.fider.io", true},- {"multi", "all-test-fider-io", "app.feedback.test.fider.io", false},- {"multi", "all-test-fider-io", "my.app.feedback.test.fider.io", false},- {"single", "test-fider-io", "test.fider.io", true},- {"single", "test-fider-io", "fider.io", true},+ {"multi", "all-test-fider-io", ""},+ {"multi", "all-test-fider-io", "fider"},+ {"multi", "all-test-fider-io", "feedback.test.fider.io"},+ {"multi", "all-test-fider-io", "FEEDBACK.test.fider.io"},+ {"single", "test-fider-io", "test.fider.io"},+ {"single", "test-fider-io", "fider.io"},}for _, testCase := range testCases {@@ -40,12 +37,7 @@ func Test_GetCertificate(t *testing.T) {ServerName: testCase.serverName,})- if testCase.valid {- Expect(err).IsNil()- Expect(cert.Certificate).Equals(wildcardCert.Certificate)- } else {- Expect(cert).IsNil()- Expect(err.Error()).ContainsSubstring(`ssl: invalid server name "` + testCase.serverName + `"`)- }+ Expect(err).IsNil()+ Expect(cert.Certificate).Equals(wildcardCert.Certificate)}}diff --git a/app/pkg/web/testdata/basic.html b/app/pkg/web/testdata/basic.htmlindex ef6df5b53..177113f02 100755--- a/app/pkg/web/testdata/basic.html+++ b/app/pkg/web/testdata/basic.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/canonical.html b/app/pkg/web/testdata/canonical.htmlindex 3af4fcd09..92c2ccd91 100755--- a/app/pkg/web/testdata/canonical.html+++ b/app/pkg/web/testdata/canonical.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png"><link rel="canonical" href="http://feedback.demo.org" />diff --git a/app/pkg/web/testdata/chunk.html b/app/pkg/web/testdata/chunk.htmlindex c43327c25..289869f5a 100644--- a/app/pkg/web/testdata/chunk.html+++ b/app/pkg/web/testdata/chunk.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/home.html b/app/pkg/web/testdata/home.htmlindex c5d3b0ded..e1313f0bd 100755--- a/app/pkg/web/testdata/home.html+++ b/app/pkg/web/testdata/home.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/home_ssr.html b/app/pkg/web/testdata/home_ssr.htmlindex 328ceff5f..21ce9913d 100755--- a/app/pkg/web/testdata/home_ssr.html+++ b/app/pkg/web/testdata/home_ssr.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/oauth.html b/app/pkg/web/testdata/oauth.htmlindex 6ac3cb946..3a94becf1 100755--- a/app/pkg/web/testdata/oauth.html+++ b/app/pkg/web/testdata/oauth.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/tenant.html b/app/pkg/web/testdata/tenant.htmlindex 1ff0c448b..3657d4593 100755--- a/app/pkg/web/testdata/tenant.html+++ b/app/pkg/web/testdata/tenant.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">diff --git a/app/pkg/web/testdata/user.html b/app/pkg/web/testdata/user.htmlindex eebf31fc3..1b9d22947 100755--- a/app/pkg/web/testdata/user.html+++ b/app/pkg/web/testdata/user.html@@ -3,9 +3,9 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=64" sizes="64x64" type="image/png">- <link rel="icon" href="https://demo.test.fider.io:3000/favicon?size=192" sizes="192x192" type="image/png">- <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/favicon?size=180&bg=white" sizes="180x180" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=64" sizes="64x64" type="image/png">+ <link rel="icon" href="https://demo.test.fider.io:3000/static/favicon?size=192" sizes="192x192" type="image/png">+ <link rel="apple-touch-icon" href="https://demo.test.fider.io:3000/static/favicon?size=180&bg=white" sizes="180x180" type="image/png">@@ -37,7 +37,7 @@<script id="server-data" type="application/json">- {"contextID":"CONTEXT_ID","description":"My Page Description","props":{},"sessionID":"","settings":{"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"mode":"multi","oauth":[]},"tenant":null,"title":"My Page Title · Fider","user":{"avatarBlobKey":"","avatarType":"gravatar","avatarURL":"https://demo.test.fider.io:3000/avatars/gravatar/5/Jon%20Snow","email":"[email protected]","id":5,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}+ {"contextID":"CONTEXT_ID","description":"My Page Description","props":{},"sessionID":"","settings":{"assetsURL":"https://demo.test.fider.io:3000","baseURL":"https://demo.test.fider.io:3000","domain":".test.fider.io","environment":"test","googleAnalytics":"","hasLegal":true,"mode":"multi","oauth":[]},"tenant":null,"title":"My Page Title · Fider","user":{"avatarBlobKey":"","avatarType":"gravatar","avatarURL":"https://demo.test.fider.io:3000/static/avatars/gravatar/5/Jon%20Snow","email":"[email protected]","id":5,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}</script>diff --git a/app/services/sqlstore/postgres/common.go b/app/services/sqlstore/postgres/common.goindex 56eabe764..2a0aeee99 100644--- a/app/services/sqlstore/postgres/common.go+++ b/app/services/sqlstore/postgres/common.go@@ -74,8 +74,8 @@ func buildAvatarURL(ctx context.Context, avatarType enum.AvatarType, id int, nam}if avatarType == enum.AvatarTypeCustom {- return web.AssetsURL(ctx, "/images/%s", avatarBlobKey)+ return web.AssetsURL(ctx, "/static/images/%s", avatarBlobKey)} else {- return web.AssetsURL(ctx, "/avatars/%s/%d/%s", avatarType.String(), id, url.PathEscape(name))+ return web.AssetsURL(ctx, "/static/avatars/%s/%d/%s", avatarType.String(), id, url.PathEscape(name))}}diff --git a/app/services/sqlstore/postgres/user_test.go b/app/services/sqlstore/postgres/user_test.goindex 98979fb4c..4e8b846f5 100644--- a/app/services/sqlstore/postgres/user_test.go+++ b/app/services/sqlstore/postgres/user_test.go@@ -29,7 +29,7 @@ func TestUserStorage_GetByID(t *testing.T) {Expect(userByID.Result.Tenant.ID).Equals(1)Expect(userByID.Result.Name).Equals("Jon Snow")Expect(userByID.Result.Email).Equals("[email protected]")- Expect(userByID.Result.AvatarURL).Equals("http://cdn.test.fider.io/avatars/gravatar/1/Jon%20Snow")+ Expect(userByID.Result.AvatarURL).Equals("http://cdn.test.fider.io/static/avatars/gravatar/1/Jon%20Snow")Expect(userByID.Result.Providers).HasLen(1)Expect(userByID.Result.Providers[0].UID).Equals("FB1234")Expect(userByID.Result.Providers[0].Name).Equals("facebook")diff --git a/public/assets/styles/utility/display.scss b/public/assets/styles/utility/display.scssindex 37042f9e4..82ba22c3c 100644--- a/public/assets/styles/utility/display.scss+++ b/public/assets/styles/utility/display.scss@@ -83,6 +83,10 @@flex-wrap: wrap;}+.align-self-start {+ align-self: start;+}+.flex-items-center {align-items: center;}@@ -108,7 +112,7 @@}}-@each $i in 2, 4 {+@each $i in 2, 4, 6 {.flex-x.flex--divide-#{$i} > *:first-child {padding-right: spacing($i);}diff --git a/public/components/VoteCounter.spec.tsx b/public/components/VoteCounter.spec.tsxindex edc3aeee5..a271c06fc 100644--- a/public/components/VoteCounter.spec.tsx+++ b/public/components/VoteCounter.spec.tsx@@ -20,7 +20,7 @@ beforeEach(() => {name: "John",role: UserRole.Collaborator,status: UserStatus.Active,- avatarURL: "/avatars/letter/5/John",+ avatarURL: "/static/avatars/letter/5/John",},hasVoted: false,response: null,diff --git a/public/pages/Home/components/ListPosts.tsx b/public/pages/Home/components/ListPosts.tsxindex 4a27559d5..93319f311 100644--- a/public/pages/Home/components/ListPosts.tsx+++ b/public/pages/Home/components/ListPosts.tsx@@ -12,8 +12,10 @@ interface ListPostsProps {const ListPostItem = (props: { post: Post; user?: CurrentUser; tags: Tag[] }) => {return (- <HStack center={false}>- <VoteCounter post={props.post} />+ <HStack center={true}>+ <div className="align-self-start">+ <VoteCounter post={props.post} />+ </div><VStack className="w-full" spacing={2}><HStack justify="between"><a className="text-title hover:text-primary-base" href={`/posts/${props.post.number}/${props.post.slug}`}>@@ -49,7 +51,7 @@ export const ListPosts = (props: ListPostsProps) => {}return (- <VStack spacing={4} divide={true}>+ <VStack spacing={4} divide={true} center={true} className="test">{props.posts.map((post) => (<ListPostItem key={post.id} post={post} tags={props.tags.filter((tag) => post.tags.indexOf(tag.slug) >= 0)} />))}diff --git a/public/services/utils.ts b/public/services/utils.tsindex a4f3fc958..07f5d2174 100644--- a/public/services/utils.ts+++ b/public/services/utils.ts@@ -135,9 +135,9 @@ export const isCookieEnabled = (): boolean => {export const uploadedImageURL = (bkey: string | undefined, size?: number): string | undefined => {if (bkey) {if (size) {- return `${Fider.settings.assetsURL}/images/${bkey}?size=${size}`+ return `${Fider.settings.assetsURL}/static/images/${bkey}?size=${size}`}- return `${Fider.settings.assetsURL}/images/${bkey}`+ return `${Fider.settings.assetsURL}/static/images/${bkey}`}return undefined}diff --git a/views/base.html b/views/base.htmlindex 9199c15a0..ae9c2d845 100644--- a/views/base.html+++ b/views/base.html@@ -52,7 +52,7 @@{{template "end-of-body" .}}{{ if .public.tenant }}{{ if .public.tenant.CustomCSS }}- <link rel="stylesheet" href="{{ .public.settings.assetsURL }}/custom/{{ .public.tenant.CustomCSS | md5 }}.css" />+ <link rel="stylesheet" href="{{ .public.settings.assetsURL }}/static/custom/{{ .public.tenant.CustomCSS | md5 }}.css" />{{ end }}{{ end }}</body>