Creates, configures, and debugs `@hapi/hapi` servers — implements routes, plugins, auth schemes, validation, caching, and request lifecycle hooks. Use when building HTTP APIs, setting up stale-while-revalidate caching, registering server methods, configuring views, managing startup sequences, or troubleshooting response marshalling.
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Creates, configures, and debugs `@hapi/hapi` servers — implements routes, plugins, auth schemes, validation, caching, and request lifecycle hooks. Use when building HTTP APIs, setting up stale-while-revalidate caching, registering server methods, configuring views, managing startup sequences, or troubleshooting response marshalling.
Auth is three layers - scheme → strategy → default; see server auth
Validate at the route - Use joi schemas on params, query, payload, headers; see validation
Type routes with Refs - Use ServerRoute<Refs> with ONLY the keys you need (Params, Query, Payload, etc.); omitted keys keep defaults. See route scaffold
Auth three-layer pattern:
server.auth.scheme('custom', schemeImpl); // 1. scheme (how to authenticate)
server.auth.strategy('session', 'custom', options); // 2. strategy (configured instance)
server.auth.default('session'); // 3. default (apply to all routes)
Scheme authenticate MUST return h.authenticated() with both credentials AND artifacts:
return h.authenticated({
credentials: { user: { id, name }, scope: ['user'] },
artifacts: { token } // always include artifacts for raw auth data
});