@ easy- cms/ next
Next.js Easy CMS (App Router, 15 或后期)的适配器: REST API 和 admin UI 的路由处理器, 和打入的 getEasyCMS() 用于服务器组件。 部分 简单 CMS,用于 Nuxt 和 Next.js 的嵌入式,代码为第一的无头 CMS.
安装
npm install @easy-cms/next @easy-cms/core @easy-cms/db-postgres
或者说 pnpm add, (中文(简体) ), yarn add 或者说 bun add。 。 。 .
使用量
1. 环绕 next.config.ts 因此服务器构建保留了管理员UI和数据库驱动程序:
import { withEasyCMS } from '@easy-cms/next/config'
export default withEasyCMS({ /* your Next config */ })
2. 增加两个路由处理器 (路径匹配) routes.api 财务报告和审定财务报表 admin.path 在您的 CMS 配置中 :
// app/api/cms/[[...path]]/route.ts
import { createRouteHandlers } from '@easy-cms/next'
import config from '@/easy-cms.config'
export const { GET, HEAD, POST, PATCH, PUT, DELETE, OPTIONS } = createRouteHandlers(config)
// app/admin/[[...path]]/route.ts
import { createAdminRouteHandlers } from '@easy-cms/next'
import config from '@/easy-cms.config'
export const { GET, HEAD } = createAdminRouteHandlers(config)
3. 在服务器组件中读取内容 输入本地 API 时 :
import { connection } from 'next/server'
import { Suspense } from 'react'
import { getEasyCMS, getEasyCMSUser } from '@easy-cms/next'
import config from '@/easy-cms.config'
export default function Page() {
return (
<Suspense>
<Posts />
</Suspense>
)
}
async function Posts() {
await connection() // read on each request
const cms = await getEasyCMS(config)
const { docs } = await cms.find('posts', { limit: 10 })
const user = await getEasyCMSUser(config) // logged-in Easy CMS user or null
// …
}
可从内容管理系统读取的页码应提供: await connection() 在一个组件中
内部 <Suspense>,如上(或有重新验证目的的缓存)。 否则 next build
尝试在预先回复时查询数据库。 这不管有没有用 cacheComponents 开始;
新应用程序来自 create-next-app 有它,还有那里 export const dynamic 不允许.
createRouteHandlers(config, { trustProxy: true }) 用途 X-Forwarded-For 限制登录率;
允许它支持您信任的代理( Vercel 和 Netlify 不被承认 ) 。 这也要
basePath 财务报告和审定财务报表 getClientIp(request)。 。 。 .
链接
下一个.js • 妇女 文档 (单位:千美元)ภาษาไทย· GitHub 图像
MIT 许可证