mcpField
F
fastify-best-practices

fastify-best-practices

github.com/ilteoood开发2535 次安装6 天前更新
代码仓库

关于 fastify-best-practices

fastify-best-practices 是为使用 Fastify 构建后端应用的开发者提供的指导技能。它按主题整理路由、插件、Schema、测试、安全和生产配置等实践与示例。

主要功能

  1. 01插件与路由开发指导
  2. 02Schema 验证和序列化模式
  3. 03错误处理与请求生命周期
  4. 04使用 Fastify inject 测试
  5. 05TypeScript、日志与部署指导

适用场景

  1. 01规划 Fastify 后端结构
  2. 02添加身份验证与钩子
  3. 03测试路由处理器
  4. 04为应用配置生产环境

安装

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

$npx skills add https://github.com/ilteoood/harness --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