Scripts2026年4月10日·1 分钟阅读

Strapi — Leading Open Source Headless CMS

Strapi is the most popular open-source headless CMS with 71K+ stars. Visual content-type builder, REST & GraphQL APIs, RBAC, and extensive plugin marketplace.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

npx create-strapi@latest my-project
cd my-project
npm run develop

Open http://localhost:1337/admin — register your admin account and start building content types.

介绍

Strapi is the leading open-source headless CMS, built with Node.js and fully customizable with JavaScript/TypeScript. It provides a visual content-type builder, auto-generated REST & GraphQL APIs, role-based access control, and a rich plugin marketplace — making it the go-to choice for developers building content-driven applications.

With 71.8K+ GitHub stars, Strapi is by far the most popular open-source headless CMS, powering thousands of production applications from personal blogs to enterprise content platforms.

What Strapi Does

Strapi provides a complete content management solution:

  • Content-Type Builder: Visual interface to define content models with fields, relations, and components
  • Auto-generated APIs: REST and GraphQL APIs created automatically from your content types
  • Media Library: Upload, organize, and transform images and files with built-in asset management
  • Authentication & RBAC: User management with role-based permissions at field and content-type level
  • Internationalization (i18n): Built-in multi-language content management
  • Content Versioning: Draft/publish workflow with content history
  • Marketplace: 100+ community plugins for SEO, email, search, and more
  • Customization: Extend with custom controllers, services, middlewares, and policies

Architecture

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Your App    │────▶│  Strapi      │────▶│  SQLite /    │
│  (Next.js /  │     │  Server      │     │  PostgreSQL /│
│  Nuxt / etc) │     │  (Koa.js)    │     │  MySQL       │
└──────────────┘     └──────┬───────┘     └──────────────┘
                            │
                     ┌──────┴───────┐
                     │  Admin Panel │
                     │  (React)     │
                     └──────────────┘

Getting Started

Create a Project

npx create-strapi@latest my-project
# Choose database: SQLite (default), PostgreSQL, or MySQL
# Choose TypeScript or JavaScript

Content Types via UI

The Content-Type Builder lets you visually create:

  • Collection Types: Repeatable content (Articles, Products, Users)
  • Single Types: Unique content (Homepage, Settings, About Page)
  • Components: Reusable field groups (SEO, Address, Social Links)

Content Types via Code

// src/api/article/content-types/article/schema.json
{
  "kind": "collectionType",
  "collectionName": "articles",
  "info": {
    "singularName": "article",
    "pluralName": "articles",
    "displayName": "Article"
  },
  "attributes": {
    "title": {
      "type": "string",
      "required": true
    },
    "content": {
      "type": "richtext"
    },
    "slug": {
      "type": "uid",
      "targetField": "title"
    },
    "cover": {
      "type": "media",
      "allowedTypes": ["images"]
    },
    "category": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "api::category.category"
    },
    "author": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "plugin::users-permissions.user"
    }
  }
}

API Usage

REST API

# List articles
curl http://localhost:1337/api/articles?populate=*

# Get single article
curl http://localhost:1337/api/articles/1?populate=cover,category

# Create article (authenticated)
curl -X POST http://localhost:1337/api/articles 
  -H "Authorization: Bearer YOUR_JWT" 
  -H "Content-Type: application/json" 
  -d '{"data": {"title": "My Post", "content": "Hello World"}}'

# Filter and sort
curl "http://localhost:1337/api/articles?filters[category][name][$eq]=tech&sort=publishedAt:desc&pagination[limit]=10"

GraphQL API

query {
  articles(
    filters: { category: { name: { eq: "tech" } } }
    sort: "publishedAt:desc"
    pagination: { limit: 10 }
  ) {
    data {
      id
      attributes {
        title
        content
        slug
        cover {
          data {
            attributes {
              url
            }
          }
        }
      }
    }
  }
}

Self-Hosting

Docker Compose

services:
  strapi:
    image: strapi/strapi:latest
    ports:
      - "1337:1337"
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
      JWT_SECRET: your-jwt-secret
      ADMIN_JWT_SECRET: your-admin-jwt-secret
      APP_KEYS: key1,key2,key3,key4
    depends_on:
      - postgres
    volumes:
      - strapi-data:/opt/app

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi
      POSTGRES_DB: strapi
    volumes:
      - pg-data:/var/lib/postgresql/data

volumes:
  strapi-data:
  pg-data:

Strapi vs Alternatives

Feature Strapi Payload Directus Contentful
Open Source Yes Yes (MIT) Yes No
GitHub Stars 71.8K 41.7K 34.7K N/A
Config GUI + code Code-first GUI GUI
Language JavaScript/TS TypeScript JavaScript N/A
Database SQLite/PG/MySQL MongoDB/PG Any SQL Hosted
Plugin marketplace 100+ Growing Extensions Apps
Community Very large Growing fast Large Large

常见问题

Q: Strapi 适合大型企业项目吗? A: 适合。Strapi v5 增强了企业功能,包括审计日志、SSO、审批流程和内容发布工作流。大量企业已在生产环境使用 Strapi。

Q: Strapi v5 和 v4 有什么区别? A: v5 改进了 API 响应格式(更扁平化)、引入了 Document Service API、改善了 TypeScript 支持、优化了数据库查询性能。从 v4 迁移需要更新 API 调用方式。

Q: 内容编辑器支持 Markdown 吗? A: 默认的富文本编辑器是 WYSIWYG 模式。通过社区插件可以替换为 Markdown 编辑器。也可以使用 CKEditor 5 插件获得更强大的编辑体验。

来源与致谢

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产