mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
feat(web): serve v1 docs on opencode.ai/docs and own the zen/go redirects (#62183)
This commit is contained in:
+17
-2
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { ALL } from "../go"
|
||||
@@ -0,0 +1 @@
|
||||
export { ALL } from "../zen"
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user