Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

help: Make canonical URL for the root to be /help/.

Shubham Padia9fa09f8f8739
diff --git a/package.json b/package.json
index 840f1af446e..ed089802e65 100644
--- a/package.json
+++ b/package.json
@@ -164,6 +164,7 @@
"svgo": "^4.0.0",
"typescript": "^5.0.2",
"typescript-eslint": "^8.13.0",
+ "vite": "^6.3.5",
"vnu-jar": "^24.10.17",
"webpack-dev-server": "^5.0.2",
"xvfb": "^0.4.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6b02a0b6aac..c6a264c4cc3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -513,6 +513,9 @@ importers:
typescript-eslint:
specifier: ^8.13.0
+ vite:
+ specifier: ^6.3.5
vnu-jar:
specifier: ^24.10.17
version: 24.10.17
@@ -8865,8 +8868,8 @@ packages:
resolution: {integrity: sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw==}
- resolution: {integrity: sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==}
+ resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==}
engines: {node: '>=12.0.0'}
@@ -13008,7 +13011,7 @@ snapshots:
shiki: 3.12.2
smol-toml: 1.4.2
tinyexec: 0.3.2
- tinyglobby: 0.2.14
+ tinyglobby: 0.2.15
tsconfck: 3.1.6([email protected])
ultrahtml: 1.6.0
unifont: 0.5.2
@@ -20388,7 +20391,7 @@ snapshots:
dependencies:
fdir: 6.5.0([email protected])
picomatch: 4.0.3
@@ -20964,7 +20967,7 @@ snapshots:
picomatch: 4.0.3
postcss: 8.5.6
rollup: 4.50.0
- tinyglobby: 0.2.14
+ tinyglobby: 0.2.15
optionalDependencies:
'@types/node': 22.18.1
fsevents: 2.3.3
diff --git a/puppet/zulip/files/nginx/zulip-include-frontend/app b/puppet/zulip/files/nginx/zulip-include-frontend/app
index d83007e8836..b9f89924876 100644
--- a/puppet/zulip/files/nginx/zulip-include-frontend/app
+++ b/puppet/zulip/files/nginx/zulip-include-frontend/app
@@ -27,8 +27,13 @@ location /static/ {
}
}
-# Redirect to links without the trailing slash.
-location ~ ^(/help(?:/[^/]+)*)/+$ {
+# Canonical URL for the root is /help/.
+location = /help {
+ return 301 /help/;
+}
+
+# Redirect to links without the trailing slash except for root /help/.
+location ~ ^(/help(?:/[^/]+)+)/+$ {
return 301 $1$is_args$args;
}
diff --git a/starlight_help/astro.config.mjs b/starlight_help/astro.config.mjs
index bbd14f3bb8e..d19f6b1b258 100644
--- a/starlight_help/astro.config.mjs
+++ b/starlight_help/astro.config.mjs
@@ -7,6 +7,53 @@ import {defineConfig, envField} from "astro/config";
import compressor from "astro-compressor";
import Icons from "unplugin-icons/vite";
+/**
+ * @returns {import("vite").PluginOption}
+ */
+function createRedirectPlugin() {
+ // Astro and starlight middlewares run after astro's vite middleware,
+ // which gives error before our logic here could run, so the only option
+ // left with us was to use a vite plugin.
+ return {
+ name: "redirect-plugin",
+ enforce: "post",
+ /**
+ * configureServer only runs in development mode, we handle the redirects
+ * in production using nginx.
+ * @param {import("vite").ViteDevServer} server
+ */
+ configureServer(server) {
+ return () => {
+ // The method exposed by the connect app at server.middlewares is `use`.
+ // But `use` appends our middleware at the end of the stack, before which
+ // the trailingSlashMiddleware of astro runs and gives an error before it
+ // can reach our middleware. `stack.unshift` ensures our middleware runs
+ // first.
+ server.middlewares.stack.unshift({
+ route: "",
+ /**
+ * @param {import("http").IncomingMessage} req
+ * @param {import("http").ServerResponse} _res
+ * @param {Function} next
+ */
+ handle(req, _res, next) {
+ // Canonical URL for the root of the help center is /help/,
+ // but for all other help URLs, there should be no trailingSlash.
+ // We have set trailingSlash to never in astro. Setting it to ignore
+ // will make our /help/ work, but it causes sidebar and other
+ // components to generate links with a trailingSlash at the end. So
+ // we manually handle this case.
+ if (req.url === "/help/") {
+ req.url = "/help";
+ }
+ next();
+ },
+ });
+ };
+ },
+ };
+}
+
// https://astro.build/config
export default defineConfig({
base: "help",
@@ -47,6 +94,7 @@ export default defineConfig({
}
},
}),
+ createRedirectPlugin(),
],
ssr: {
noExternal: ["zod"],
diff --git a/version.py b/version.py
index 1e2284f2b19..d64718a7d98 100644
--- a/version.py
+++ b/version.py
@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 427
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
-PROVISION_VERSION = (351, 1) # bumped 2025-10-02 to add PyICU
+PROVISION_VERSION = (351, 2) # bumped 2025-10-01 to add vite to starlight_help