@ -1,27 +1,15 @@
|
||||
---
|
||||
import Layout from "@/layouts/Layout.astro"
|
||||
import Article from "@/components/pages/article.astro"
|
||||
import { fetchArticleById } from "@/lib/data"
|
||||
import { getSsrArticle } from "@/lib/ssr"
|
||||
|
||||
// 按需 SSR:服务端按 ?id= 取数并渲染(保留既有 /cn/article?id= 链接,无需改动其他页面)
|
||||
export const prerender = false
|
||||
|
||||
const API = (import.meta.env.API_SSR || import.meta.env.PUBLIC_API_BASE || "http://localhost:8090").replace(/\/$/, "")
|
||||
const id = Astro.url.searchParams.get("id")
|
||||
let article: import("@/lib/data").RawArticle | null = null
|
||||
let error: "missing" | "failed" | null = null
|
||||
if (!id) {
|
||||
error = "missing"
|
||||
} else {
|
||||
try {
|
||||
article = await fetchArticleById(id, API)
|
||||
} catch {
|
||||
article = null
|
||||
}
|
||||
error = article ? null : "failed"
|
||||
}
|
||||
const { article, error } = await getSsrArticle(id)
|
||||
---
|
||||
|
||||
<Layout>
|
||||
<Article article={article} locale="cn" apiBase={API} error={error} />
|
||||
<Article article={article} locale="cn" error={error} />
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user