mcpField
F
fastify-best-practices

fastify-best-practices

github.com/mcollina开发2.0k84.8k 次安装1 周前更新
代码仓库

关于 fastify-best-practices

面向后端开发者的 Fastify 技能,涵盖插件、路由、模式、测试和生产环境实践。

主要功能

  1. 01插件与路由设计
  2. 02模式验证与序列化
  3. 03错误处理与请求钩子
  4. 04身份验证与安全模式
  5. 05使用 inject() 测试
  6. 06性能与部署指导

适用场景

  1. 01组织 Fastify 后端结构
  2. 02添加基于模式的请求验证
  3. 03使用 inject() 测试路由
  4. 04为生产环境准备 Fastify 服务

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mcollina/skills --skill fastify-best-practices

安装后在 Claude Code 中输入/fastify-best-practices确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

tile.json
rules/
authentication.md
configuration.md
content-type.md
cors-security.md
database.md
decorators.md
deployment.md
error-handling.md
hooks.md
http-proxy.md
logging.md
performance.md
plugins.md
routes.md
schemas.md
serialization.md
testing.md
typescript.md
websockets.md

详细介绍

适用场景

在以下情况下使用此技能:

  • 使用 Fastify 开发后端应用
  • 实现 Fastify 插件和路由处理程序
  • 获取有关 Fastify 架构和模式的指导
  • 在 Fastify 中使用 TypeScript(剥离类型)
  • 使用 Fastify 的 inject 方法实现测试
  • 配置验证、序列化和错误处理

快速开始

一个精简且可运行的 Fastify 服务,可立即上手:

import Fastify from 'fastify'

const app = Fastify({ logger: true })

app.get('/health', async (request, reply) => {
  return { status: 'ok' }
})

const start = async () => {
  await app.listen({ port: 3000, host: '0.0.0.0' })
}
start()

常见场景的推荐阅读顺序

  • 刚接触 Fastify? 从 plugins.md → routes.md → schemas.md 开始
  • 添加身份验证: plugins.md → hooks.md → authentication.md
  • 提升性能: schemas.md → serialization.md → performance.md
  • 设置测试: routes.md → testing.md
  • 准备投入生产: logging.md → configuration.md → deployment.md

使用方法

阅读各规则文件,了解详细说明和代码示例:

核心原则

  • 封装: Fastify 的插件系统可自动实现封装
  • Schema 优先: 为验证和序列化定义 Schema
  • 性能: Fastify 针对速度进行了优化;请正确使用其功能
  • Async/await: 所有处理程序和 Hook 都支持异步函数
  • 最少依赖: 优先使用 Fastify 内置功能和官方插件

评论

支持 Markdown