AgentSkillsCN

hapi

适用于构建 Hapi.js 服务器、路由、插件或认证方案时使用。涵盖生命周期、校验、缓存、TypeScript,以及所有服务器 API。

SKILL.md
--- frontmatter
name: hapi
description: "Use when building hapi.js servers, routes, plugins, or auth schemes. Covers lifecycle, validation, caching, TypeScript, and all server APIs."
license: MIT

Hapi

Quick Start

code
const server = Hapi.server({ port: 3000 });
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
await server.start();

Critical Rules

  1. Compose with decorations & methods - Expose services via decorations and reusable logic via methods
  2. Follow the lifecycle - 24-step request flow; see lifecycle overview
  3. Auth is three layers - scheme → strategy → default; see server auth
  4. Validate at the route - Use joi schemas on params, query, payload, headers; see validation
  5. Type routes with Refs - Use ServerRoute<Refs> pattern; see route scaffold

Workflow

  1. Create server - server overview for constructor options
  2. Register plugins - plugins and plugin structure
  3. Configure auth - auth schemes and route auth
  4. Define routes - route overview with handlers
  5. Add extensions - lifecycle hooks and pre-handlers

Key Patterns

TopicReference
Request/response objectsrequest, response
Response toolkit (h)toolkit
Caching & CORScache-cors, server cache
Security headerssecurity
Payload parsingpayload
Decorations & methodsdecorations, methods
Eventsevents
Testing (server.inject)network
TypeScript auth typingauth-scheme, type-author
TypeScript pluginsplugin-scaffold