diff --git a/puppet/zulip/files/nginx/zulip-include-frontend/app b/puppet/zulip/files/nginx/zulip-include-frontend/app index 48fb93760b..2582fbbde7 100644 --- a/puppet/zulip/files/nginx/zulip-include-frontend/app +++ b/puppet/zulip/files/nginx/zulip-include-frontend/app @@ -29,7 +29,8 @@ location /static/ { # Serve help center generated by astro/starlight. location /help { - alias /home/zulip/deployments/current/starlight_help/dist/; + alias $help_alias; + gzip on; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; @@ -46,7 +47,8 @@ location /help { # These files are hashed and thus immutable; cache them aggressively. # https://github.com/withastro/docs/blob/53603ad048e8aedbca1aed77bac8eb00dcada79d/src/content/docs/en/guides/integrations-guide/node.mdx?plain=1#L304 location /help/_astro/ { - alias /home/zulip/deployments/current/starlight_help/dist/_astro/; + set $help_cache_alias "${help_alias}_astro/"; + alias $help_cache_alias; add_header Cache-Control "public, max-age=31536000, immutable"; } diff --git a/puppet/zulip/templates/nginx.conf.template.erb b/puppet/zulip/templates/nginx.conf.template.erb index 84e46bbd8f..2e4c0650f7 100644 --- a/puppet/zulip/templates/nginx.conf.template.erb +++ b/puppet/zulip/templates/nginx.conf.template.erb @@ -61,4 +61,9 @@ http { include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; + + map $host $help_alias { + zulip.com /home/zulip/deployments/current/starlight_help/dist_no_relative_links/; + default /home/zulip/deployments/current/starlight_help/dist/; + } } diff --git a/starlight_help/.gitignore b/starlight_help/.gitignore index c2defb434b..94ce928b19 100644 --- a/starlight_help/.gitignore +++ b/starlight_help/.gitignore @@ -1,5 +1,6 @@ # build output dist/ +dist_no_relative_links/ # generated types .astro/ diff --git a/tools/build-help-center b/tools/build-help-center index 960e3242c2..8273f4997c 100755 --- a/tools/build-help-center +++ b/tools/build-help-center @@ -26,6 +26,13 @@ parser.add_argument( dest="show_relative_links", help="Disable relative links when using NavigationSteps component. Typically only set to true in case of the help center being hosted on zulip.com.", ) + +parser.add_argument( + "--out-dir", + action="store", + dest="out_dir", + help="Output directory for the final build.", +) args = parser.parse_args() @@ -34,8 +41,12 @@ def run() -> None: env["SUPPORT_EMAIL"] = parseaddr(settings.ZULIP_ADMINISTRATOR)[1] env["CORPORATE_ENABLED"] = str(settings.CORPORATE_ENABLED).lower() env["SHOW_RELATIVE_LINKS"] = str(args.show_relative_links).lower() + build_command = ["/usr/local/bin/corepack", "pnpm", "build"] + if args.out_dir: + build_command += ["--outDir", args.out_dir] + subprocess.check_call( - ["/usr/local/bin/corepack", "pnpm", "build"], + build_command, cwd="starlight_help", env=env, ) diff --git a/tools/update-prod-static b/tools/update-prod-static index 45047c3f17..040f91edce 100755 --- a/tools/update-prod-static +++ b/tools/update-prod-static @@ -46,17 +46,20 @@ run(["./tools/setup/build_timezone_values"]) # need them. if settings.CORPORATE_ENABLED: run(["./tools/setup/generate_landing_page_images.py"]) - # We ideally should be generating two builds for Zulip cloud - # and serve a different one depending on whether the subdomain - # is same as the root domain or not. - run(["./tools/build-help-center", "--no-relative-links"]) -else: - run(["./tools/build-help-center"]) + run( + [ + "./tools/build-help-center", + "--no-relative-links", + "--out-dir", + "./dist_no_relative_links", + ] + ) + +run(["./tools/build-help-center"]) # Create webpack bundle run(["./tools/webpack", "--quiet"]) - # Collect the files that we're going to serve; this creates prod-static/serve. run(["./manage.py", "collectstatic", "-v0", "--noinput"])