UNPKG

doc-it-up

Version:

Generates automatic documentation for your code. Supports Express, Fastify, Koa, Hono, Elysia, and Hapi.

43 lines (40 loc) 1.59 kB
import { _ as __awaiter } from '../chunks/tslib.es6-WQS2tr1v.js'; import { initDocsDirectory, DocItUpCore } from '../core.js'; import 'fs/promises'; import 'path'; const docItUpElysia = (options = {}) => (app) => { if (options.docsDir) initDocsDirectory(options.docsDir); else initDocsDirectory(); return app .onAfterHandle((_a) => __awaiter(void 0, [_a], void 0, function* ({ request, set, body, params, query, response }) { const url = new URL(request.url); if (url.pathname.startsWith('/docs')) return; const statusCode = set.status || 200; if (typeof statusCode === 'number' && statusCode >= 200 && statusCode < 300) { DocItUpCore.recordRequest({ method: request.method, path: url.pathname, headers: Object.fromEntries(request.headers.entries()), query: query || {}, body: body, params: params || {} }, { statusCode: statusCode, headers: set.headers, body: response }); } })) .get('/docs', () => __awaiter(void 0, void 0, void 0, function* () { yield DocItUpCore.loadSpecs(); return new Response(DocItUpCore.getHtml(), { headers: { 'Content-Type': 'text/html' } }); })) .get('/docs/swagger.json', () => __awaiter(void 0, void 0, void 0, function* () { yield DocItUpCore.loadSpecs(); return DocItUpCore.getSwaggerSpec(); })); }; export { docItUpElysia };