CMS 快速开始
这一页带你从零到「读出一条自己创建的内容」。
| 依赖 | 版本 |
|---|---|
| Node.js | 22 或更高 |
| pnpm | 10 或更高 |
| 数据库 | PostgreSQL 16+ 或 SQLite 3.40+ |
pnpm add @hhl/cms定义内容模型
Section titled “定义内容模型”内容结构写在 cms.config.ts 里,随代码一起进版本库:
import { defineConfig, field } from '@hhl/cms';
export default defineConfig({ collections: { post: { fields: { title: field.string({ required: true }), slug: field.slug({ from: 'title' }), body: field.richText(), publishedAt: field.date(), }, }, },});pnpm cms dev默认监听 http://localhost:8787。第一次启动会自动建表。
写入并读回一条内容
Section titled “写入并读回一条内容”curl -X POST http://localhost:8787/api/collections/post \ -H 'content-type: application/json' \ -d '{"title":"第一篇","body":"你好"}'然后读取:
curl http://localhost:8787/api/collections/post能看到刚才那条数据,就说明整条链路是通的。下一步去看 API 参考,把它接到你的前端。

