From 674e06bbdcf46eba8fc7970d822e18edaaaedb68 Mon Sep 17 00:00:00 2001 From: krzysdz Date: Tue, 19 May 2026 21:41:52 +0200 Subject: [PATCH 1/2] fix: add missing redirects Fixes #2327 Fixes #2328 Fixes #2332 --- src/config/redirect.js | 97 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/src/config/redirect.js b/src/config/redirect.js index c6a4bae5d9..3be3c1d665 100644 --- a/src/config/redirect.js +++ b/src/config/redirect.js @@ -1,5 +1,30 @@ // Redirect .html and non-.html blog post URLs to the new format. This will ensure that any existing links to blog posts will continue to work and redirect users to the correct location on the new site. +import { getLanguageCodes } from '../i18n/utils'; + +/** @param {{[key: string]: string}} pageMap */ +function localizedPages(pageMap) { + /** @type {{[key: string]: string}} */ + const localizedVersions = {}; + const languageCodes = getLanguageCodes(); + for (const [from, to] of Object.entries(pageMap)) { + // All localized pages seem to have had both / and /en/ versions + localizedVersions[`/${from}`] = `/en/${to}`; + for (const langCode of languageCodes) { + localizedVersions[`/${langCode}/${from}`] = `/${langCode}/${to}`; + } + } + return localizedVersions; +} + +/** @param {string[]} pageList */ +function stripHTML(pageList) { + return Object.fromEntries(pageList.map((old) => [old, old.substring(0, old.length - 5)])); +} + const blog = { + '/blog/posts.html': '/en/blog', + '/en/blog/posts.html': '/en/blog', + '/en/blog/write-post.html': '/en/blog/write-post/', '/2024/07/16/welcome-post.html': '/en/blog/2024-07-16-welcome-post', '/2024/07/16/welcome-post': '/en/blog/2024-07-16-welcome-post', '/2024/09/29/security-releases.html': '/en/blog/2024-09-29-security-releases', @@ -60,10 +85,80 @@ const api_v2 = { }; const pages = { + '/changelog/4x.html': 'https://github.com/expressjs/express/releases', '/en/changelog/4x.html': 'https://github.com/expressjs/express/releases', '/en/changelog/4x': 'https://github.com/expressjs/express/releases', }; -const redirects = { ...blog, ...api_v2, ...pages }; +const api = localizedPages({ + 'api.html': '5x/api/', + '3x/api.html': '3x/api/', + '4x/api.html': '4x/api/', + '5x/api.html': '5x/api/', +}); + +const localizedGuides = localizedPages( + stripHTML([ + 'advanced/best-practice-performance.html', + 'advanced/best-practice-security.html', + 'advanced/developing-template-engines.html', + 'advanced/healthcheck-graceful-shutdown.html', + 'advanced/security-updates.html', + 'guide/behind-proxies.html', + 'guide/database-integration.html', + 'guide/debugging.html', + 'guide/error-handling.html', + 'guide/migrating-4.html', + 'guide/migrating-5.html', + 'guide/overriding-express-api.html', + 'guide/routing.html', + 'guide/using-middleware.html', + 'guide/using-template-engines.html', + 'guide/writing-middleware.html', + 'starter/basic-routing.html', + 'starter/examples.html', + 'starter/faq.html', + 'starter/generator.html', + 'starter/hello-world.html', + 'starter/installing.html', + 'starter/static-files.html', + ]) +); + +const localizedResources = localizedPages( + stripHTML([ + 'resources/community.html', + 'resources/contributing.html', + 'resources/glossary.html', + 'resources/middleware/body-parser.html', + 'resources/middleware/compression.html', + 'resources/middleware/connect-rid.html', + 'resources/middleware/cookie-parser.html', + 'resources/middleware/cookie-session.html', + 'resources/middleware/cors.html', + 'resources/middleware/errorhandler.html', + 'resources/middleware/method-override.html', + 'resources/middleware/morgan.html', + 'resources/middleware/multer.html', + 'resources/middleware/response-time.html', + 'resources/middleware/serve-favicon.html', + 'resources/middleware/serve-index.html', + 'resources/middleware/serve-static.html', + 'resources/middleware/session.html', + 'resources/middleware/timeout.html', + 'resources/middleware/vhost.html', + 'resources/middleware.html', + 'resources/utils.html', + ]) +); + +const redirects = { + ...blog, + ...api_v2, + ...pages, + ...api, + ...localizedGuides, + ...localizedResources, +}; export default redirects; From 808751a789e0c23e784e48008413019dd6ba2ea8 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Sun, 21 Jun 2026 15:33:57 -0500 Subject: [PATCH 2/2] feat: implement HTML redirects for legacy URLs and update build configuration --- netlify.toml | 3 - package.json | 2 +- src/config/redirect.js | 150 +++++++------------------------------- src/pages/[...path].astro | 76 +++++++++++++++++++ 4 files changed, 102 insertions(+), 129 deletions(-) create mode 100644 src/pages/[...path].astro diff --git a/netlify.toml b/netlify.toml index 72ac9b9d5f..a1680b2fff 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,3 @@ [build] command = "npm run build" publish = "dist" - -[build.environment] - NODE_OPTIONS = "--max-old-space-size=4096" diff --git a/package.json b/package.json index 06aab853a3..6ed5fe76c9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "dev": "astro dev", - "build": "astro build", + "build": "NODE_OPTIONS=--max-old-space-size=4096 astro build", "preview": "astro preview", "astro": "astro", "lint": "eslint .", diff --git a/src/config/redirect.js b/src/config/redirect.js index 3be3c1d665..c087453300 100644 --- a/src/config/redirect.js +++ b/src/config/redirect.js @@ -1,164 +1,64 @@ -// Redirect .html and non-.html blog post URLs to the new format. This will ensure that any existing links to blog posts will continue to work and redirect users to the correct location on the new site. -import { getLanguageCodes } from '../i18n/utils'; - -/** @param {{[key: string]: string}} pageMap */ -function localizedPages(pageMap) { - /** @type {{[key: string]: string}} */ - const localizedVersions = {}; - const languageCodes = getLanguageCodes(); - for (const [from, to] of Object.entries(pageMap)) { - // All localized pages seem to have had both / and /en/ versions - localizedVersions[`/${from}`] = `/en/${to}`; - for (const langCode of languageCodes) { - localizedVersions[`/${langCode}/${from}`] = `/${langCode}/${to}`; - } - } - return localizedVersions; -} - -/** @param {string[]} pageList */ -function stripHTML(pageList) { - return Object.fromEntries(pageList.map((old) => [old, old.substring(0, old.length - 5)])); -} +// Legacy/external URL remaps that can't be derived from the content collections: +// old blog permalinks, links to the archived v2 docs, and the changelog page +// that now lives on GitHub. +// +// Everything else is handled elsewhere, so it's intentionally absent here: +// - The systematic "non-localized path → /en/…" redirects (guides, resources, +// api, blog posts) are generated from the content collections by +// `src/pages/[...path].astro`. +// - Stripping the `.html` extension is handled by Cloudflare, so paths are +// written without it (e.g. `/2x/guide`, not `/2x/guide.html`). const blog = { - '/blog/posts.html': '/en/blog', - '/en/blog/posts.html': '/en/blog', - '/en/blog/write-post.html': '/en/blog/write-post/', - '/2024/07/16/welcome-post.html': '/en/blog/2024-07-16-welcome-post', + '/blog/posts': '/en/blog', '/2024/07/16/welcome-post': '/en/blog/2024-07-16-welcome-post', - '/2024/09/29/security-releases.html': '/en/blog/2024-09-29-security-releases', '/2024/09/29/security-releases': '/en/blog/2024-09-29-security-releases', - '/2024/10/01/HeroDevs-partnership-announcement.html': - '/en/blog/2024-10-01-herodevs-partnership-announcement', '/2024/10/01/HeroDevs-partnership-announcement': '/en/blog/2024-10-01-herodevs-partnership-announcement', '/2024/10/15/v5-release': '/en/blog/2024-10-15-v5-release', - '/2024/10/15/v5-release.html': '/en/blog/2024-10-15-v5-release', - '/2024/10/22/security-audit-milestone-achievement.html': - '/en/blog/2024-10-22-security-audit-milestone-achievement', '/2024/10/22/security-audit-milestone-achievement': '/en/blog/2024-10-22-security-audit-milestone-achievement', - '/2025/01/09/rewind-2024-triumphs-and-2025-vision.html': - '/en/blog/2025-01-09-rewind-2024-triumphs-and-2025-vision', '/2025/01/09/rewind-2024-triumphs-and-2025-vision': '/en/blog/2025-01-09-rewind-2024-triumphs-and-2025-vision', - '/2025/03/31/v5-1-latest-release.html': '/en/blog/2025-03-31-v5-1-latest-release', '/2025/03/31/v5-1-latest-release': '/en/blog/2025-03-31-v5-1-latest-release', - '/2025/05/16/express-cleanup-legacy-packages.html': - '/en/blog/2025-05-16-express-cleanup-legacy-packages', '/2025/05/16/express-cleanup-legacy-packages': '/en/blog/2025-05-16-express-cleanup-legacy-packages', - '/2025/05/19/security-releases.html': '/en/blog/2025-05-19-security-releases', '/2025/05/19/security-releases': '/en/blog/2025-05-19-security-releases', - '/2025/06/05/vulnerability-reporting-process-overhaul.html': - '/en/blog/2025-06-05-vulnerability-reporting-process-overhaul', '/2025/06/05/vulnerability-reporting-process-overhaul': '/en/blog/2025-06-05-vulnerability-reporting-process-overhaul', - '/2025/07/18/security-releases.html': '/en/blog/2025-07-18-security-releases', '/2025/07/18/security-releases': '/en/blog/2025-07-18-security-releases', - '/2025/07/31/security-releases.html': '/en/blog/2025-07-31-security-releases', '/2025/07/31/security-releases': '/en/blog/2025-07-31-security-releases', - '/2025/12/01/security-releases.html': '/en/blog/2025-12-01-security-releases', '/2025/12/01/security-releases': '/en/blog/2025-12-01-security-releases', - '/2026/02/27/security-releases.html': '/en/blog/2026-02-27-security-releases', '/2026/02/27/security-releases': '/en/blog/2026-02-27-security-releases', - '/2026/03/30/security-releases.html': '/en/blog/2026-03-30-security-releases', '/2026/03/30/security-releases': '/en/blog/2026-03-30-security-releases', }; const api_v2 = { '/2x/': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/guide.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/migrate.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/screencasts.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/executables.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/contrib.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/applications.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/guide.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/migrate.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/screencasts.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/executables.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/contrib.html': 'https://github.com/expressjs/expressjs.com/tree/2x', - '/2x/docs/applications.html': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/guide': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/migrate': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/screencasts': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/executables': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/contrib': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/applications': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/guide': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/migrate': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/screencasts': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/executables': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/contrib': 'https://github.com/expressjs/expressjs.com/tree/2x', + '/2x/docs/applications': 'https://github.com/expressjs/expressjs.com/tree/2x', }; const pages = { - '/changelog/4x.html': 'https://github.com/expressjs/express/releases', - '/en/changelog/4x.html': 'https://github.com/expressjs/express/releases', + '/changelog/4x': 'https://github.com/expressjs/express/releases', '/en/changelog/4x': 'https://github.com/expressjs/express/releases', }; -const api = localizedPages({ - 'api.html': '5x/api/', - '3x/api.html': '3x/api/', - '4x/api.html': '4x/api/', - '5x/api.html': '5x/api/', -}); - -const localizedGuides = localizedPages( - stripHTML([ - 'advanced/best-practice-performance.html', - 'advanced/best-practice-security.html', - 'advanced/developing-template-engines.html', - 'advanced/healthcheck-graceful-shutdown.html', - 'advanced/security-updates.html', - 'guide/behind-proxies.html', - 'guide/database-integration.html', - 'guide/debugging.html', - 'guide/error-handling.html', - 'guide/migrating-4.html', - 'guide/migrating-5.html', - 'guide/overriding-express-api.html', - 'guide/routing.html', - 'guide/using-middleware.html', - 'guide/using-template-engines.html', - 'guide/writing-middleware.html', - 'starter/basic-routing.html', - 'starter/examples.html', - 'starter/faq.html', - 'starter/generator.html', - 'starter/hello-world.html', - 'starter/installing.html', - 'starter/static-files.html', - ]) -); - -const localizedResources = localizedPages( - stripHTML([ - 'resources/community.html', - 'resources/contributing.html', - 'resources/glossary.html', - 'resources/middleware/body-parser.html', - 'resources/middleware/compression.html', - 'resources/middleware/connect-rid.html', - 'resources/middleware/cookie-parser.html', - 'resources/middleware/cookie-session.html', - 'resources/middleware/cors.html', - 'resources/middleware/errorhandler.html', - 'resources/middleware/method-override.html', - 'resources/middleware/morgan.html', - 'resources/middleware/multer.html', - 'resources/middleware/response-time.html', - 'resources/middleware/serve-favicon.html', - 'resources/middleware/serve-index.html', - 'resources/middleware/serve-static.html', - 'resources/middleware/session.html', - 'resources/middleware/timeout.html', - 'resources/middleware/vhost.html', - 'resources/middleware.html', - 'resources/utils.html', - ]) -); - const redirects = { ...blog, ...api_v2, ...pages, - ...api, - ...localizedGuides, - ...localizedResources, }; export default redirects; diff --git a/src/pages/[...path].astro b/src/pages/[...path].astro new file mode 100644 index 0000000000..5149a115f4 --- /dev/null +++ b/src/pages/[...path].astro @@ -0,0 +1,76 @@ +--- +// English redirects for every content collection. +// +// The site serves all content under `/[lang]/…`, so a bare path with no locale +// prefix (an old inbound link, or what's left after Cloudflare strips `.html`) +// has no page of its own. This catch-all enumerates the same collections the +// real routes use via `getCollection`, so the slugs always match the generated +// pages, and redirects each one to its `/en/` home. +// +// The redirect HTML is rendered by hand (rather than `Astro.redirect`) so the +// meta refresh fires instantly (`0;`) — Astro's static `Astro.redirect` helper +// hardcodes a 2-second delay, which is a poor redirect experience. +import { getCollection } from 'astro:content'; +import { DEFAULT_VERSION } from '@config/versions'; + +export async function getStaticPaths() { + const [docs, pages, api, blog] = await Promise.all([ + getCollection('docs'), + getCollection('pages'), + getCollection('api'), + getCollection('blog'), + ]); + + /** @type {Set} */ + const slugs = new Set(); + + /** @param {string} slug */ + const add = (slug) => { + if (!slug) return; + slugs.add(slug); + // Pages served at the default version are also available unversioned, + // e.g. `5x/starter/installing` → `starter/installing`. + if (slug.startsWith(`${DEFAULT_VERSION}/`)) { + slugs.add(slug.slice(DEFAULT_VERSION.length + 1)); + } + }; + + // `docs` (versioned guides/starter/…) and `pages` (resources, support, …) + // both embed the language as the first id segment; only English is canonical. + for (const entry of [...docs, ...pages]) { + const [lang, ...rest] = entry.id.split('/'); + if (lang !== 'en') continue; + add(rest.join('/')); + } + + // `api` is a shared collection with `/` ids and no language. + for (const entry of api) { + add(entry.id); + } + + // `blog` is served under `/[lang]/blog/`. + for (const entry of blog) { + slugs.add(`blog/${entry.id}`); + } + slugs.add('blog'); + + return [...slugs].map((path) => ({ params: { path } })); +} + +const target = `/en/${Astro.params.path}`; +const canonical = new URL(target, Astro.site).href; +--- + + + + + + Redirecting to {target} + + + + + + Redirecting to {target} + +