Skip to content

Commit cf6a7c7

Browse files
committed
fix(site): keep the locale in legacy Console redirects
1 parent 56aca79 commit cf6a7c7

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎services/site/src/lib/legacy.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Locale } from "~/lib/language"
1+
import { consoleRoute, type Locale } from "~/lib/language"
22
import { desktopAssets, updateApi } from "~/lib/download"
33

44
// LEGACY REDIRECTS, every one to be removed later. Old URLs that outside links, bookmarks, scripts
@@ -32,7 +32,7 @@ export function legacyRedirect(request: Legacy): Response | undefined {
3232
// links (`/go` about 75k requests a day, `/zen` 46k). Exact paths only: /zen/v1/* and /zen/go/v1/*
3333
// are the inference API, which a prefix match here would break.
3434
const moved = (request.locale ? localizedMoves : moves).get(request.path.replace(/(.)\/$/, "$1"))
35-
if (moved && read) return redirect(301, `${moved}${request.search}`)
35+
if (moved && read) return redirect(301, `${request.locale ? consoleRoute(request.locale, moved) : moved}${request.search}`)
3636

3737
// The legacy dashboard and its sign-in, now the Console. The V1 CLI's "create a key at /auth" and
3838
// V1's usage-limit link /workspace/<id>/go (about 50k requests a day).
@@ -83,7 +83,8 @@ const moves = new Map([
8383
["/enterprise", "/console/enterprise"],
8484
])
8585

86-
// The old site rendered these three pages in every language; their localized URLs follow them.
86+
// The old site rendered these three pages in every language; their localized URLs follow them, and a
87+
// non-English URL keeps its language in the Console page it redirects to.
8788
const localizedMoves = new Map([
8889
["/go", "/console/go"],
8990
["/zen", "/console/models"],

‎services/site/test/legacy.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ describe("legacy redirects", () => {
4040
expect(get("/go", { method: "POST" })).toBeUndefined()
4141
})
4242

43-
test("localized go, zen and enterprise follow to the Console; other localized moves don't", () => {
44-
expect(get("/enterprise", { locale: "de" })?.headers.get("Location")).toBe("/console/enterprise")
43+
test("localized go, zen and enterprise follow to the Console in their language; other localized moves don't", () => {
44+
expect(get("/go", { locale: "de" })?.headers.get("Location")).toBe("/de/console/go")
45+
expect(get("/zen", { locale: "de" })?.headers.get("Location")).toBe("/de/console/models")
46+
expect(get("/zen", { locale: "de", search: "?ref=app" })?.headers.get("Location")).toBe(
47+
"/de/console/models?ref=app",
48+
)
49+
expect(get("/enterprise", { locale: "de" })?.headers.get("Location")).toBe("/de/console/enterprise")
4550
expect(get("/pricing", { locale: "de" })).toBeUndefined()
4651
})
4752

0 commit comments

Comments
 (0)