diff --git a/infra/app.ts b/infra/app.ts index d413dab7cdd..c6701797a4f 100644 --- a/infra/app.ts +++ b/infra/app.ts @@ -1,4 +1,4 @@ -import { domain } from "./stage" +import { domain, zoneID } from "./stage" const GITHUB_APP_ID = new sst.Secret("GITHUB_APP_ID") const GITHUB_APP_PRIVATE_KEY = new sst.Secret("GITHUB_APP_PRIVATE_KEY") @@ -17,7 +17,7 @@ export const api = new sst.cloudflare.Worker("Api", { }, }) -new sst.cloudflare.x.Astro("Web", { +const web = new sst.cloudflare.x.Astro("Web", { domain: "docs." + domain, path: "packages/web", environment: { @@ -26,3 +26,18 @@ new sst.cloudflare.x.Astro("Web", { VITE_API_URL: api.url.apply((url) => url!), }, }) + +// The site serves itself under /docs, so these routes take /docs on the main host. `sst dev` deploys no Worker. +const webServer = web.nodes.server +if (webServer) { + for (const [name, pattern] of [ + ["WebDocsRoute", `${domain}/docs`], + ["WebDocsPathRoute", `${domain}/docs/*`], + ]) { + new cloudflare.WorkersRoute(name, { + zoneId: zoneID, + pattern, + script: webServer.nodes.worker.scriptName, + }) + } +} diff --git a/packages/web/src/middleware.ts b/packages/web/src/middleware.ts index cf9f97b0b13..51524486360 100644 --- a/packages/web/src/middleware.ts +++ b/packages/web/src/middleware.ts @@ -78,6 +78,9 @@ function localeFromAcceptLanguage(header: string | null) { } export const onRequest = defineMiddleware((ctx, next) => { + // Moved Zen and Go pages redirect from their own routes, even under a locale alias like /docs/zh/go. + if (/^\/docs\/(?:[^/]+\/)?(zen|go)\/?$/.test(ctx.url.pathname)) return next() + const alias = docsAlias(ctx.url.pathname) if (alias) { return redirect(ctx.url, alias.path, alias.locale) diff --git a/packages/web/src/pages/[locale]/go.ts b/packages/web/src/pages/[locale]/go.ts new file mode 100644 index 00000000000..1b707105fa3 --- /dev/null +++ b/packages/web/src/pages/[locale]/go.ts @@ -0,0 +1 @@ +export { ALL } from "../go" diff --git a/packages/web/src/pages/[locale]/zen.ts b/packages/web/src/pages/[locale]/zen.ts new file mode 100644 index 00000000000..edde11ef833 --- /dev/null +++ b/packages/web/src/pages/[locale]/zen.ts @@ -0,0 +1 @@ +export { ALL } from "../zen" diff --git a/packages/web/src/pages/go.ts b/packages/web/src/pages/go.ts new file mode 100644 index 00000000000..917be496f07 --- /dev/null +++ b/packages/web/src/pages/go.ts @@ -0,0 +1,5 @@ +import type { APIRoute } from "astro" + +// The Go docs moved to the V2 Console docs, which only exist on the main site, so the target is absolute for +// requests on docs.opencode.ai. +export const ALL: APIRoute = (ctx) => ctx.redirect(new URL("/v2/docs/console/go/", import.meta.env.SITE).href, 302) diff --git a/packages/web/src/pages/zen.ts b/packages/web/src/pages/zen.ts new file mode 100644 index 00000000000..35e0c99a2c3 --- /dev/null +++ b/packages/web/src/pages/zen.ts @@ -0,0 +1,5 @@ +import type { APIRoute } from "astro" + +// The Zen docs moved to the V2 Console docs, which only exist on the main site, so the target is absolute for +// requests on docs.opencode.ai. +export const ALL: APIRoute = (ctx) => ctx.redirect(new URL("/v2/docs/console/models/", import.meta.env.SITE).href, 302)