diff --git a/src/server.ts b/src/server.ts index d5978fe..79e715e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -46,15 +46,54 @@ async function bootstrap() { openapi: { info: { title: 'Project Dash API', - description: 'Backend API documentation for Project Dash application.', + description: ` +# GitHub Dashboard Backend API + +Backend API for the Project Dash application - A modern GitHub repository dashboard with real-time statistics and analytics. + +## Features +- 🔐 GitHub OAuth Authentication +- 📊 Repository Statistics & Analytics +- 🔔 GitHub Webhook Integration +- ⚡ Redis Caching for Performance + +## Authentication +Most endpoints require authentication via JWT token. + +**How to authenticate:** +1. Login via \`POST /auth/login\` with GitHub OAuth code +2. Use the returned JWT token in the \`Authorization\` header: \`Bearer \` + +## Rate Limiting +GitHub API rate limits apply. Authenticated requests: 5,000/hour. + `, version: '1.0.0', + contact: { + name: 'API Support', + url: 'https://github.com/yourusername/proj-dash-backend', + }, + license: { + name: 'Apache 2.0', + url: 'https://www.apache.org/licenses/LICENSE-2.0.html', + }, }, + servers: [ + { + url: 'http://localhost:3333', + description: 'Local development server', + }, + { + url: 'https://api.projectdash.example.com', + description: 'Production server', + }, + ], components: { securitySchemes: { bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT', + description: 'Enter your JWT token obtained from `/auth/login`', }, }, }, @@ -63,11 +102,28 @@ async function bootstrap() { bearerAuth: [], }, ], + tags: [ + { + name: 'auth', + description: 'Authentication endpoints', + }, + { + name: 'repos', + description: 'Repository management and statistics', + }, + { + name: 'stats', + description: 'User statistics and analytics', + }, + { + name: 'webhooks', + description: 'GitHub webhook handlers', + }, + ], }, }) - // --- Docs portal --- - // Top-level docs landing page that links to multiple renderers (ReDoc, Stoplight Elements, RapiDoc) + app.get('/docs', (_, reply) => { reply.type('text/html').send(` @@ -75,153 +131,33 @@ async function bootstrap() { - API Documentation + API Docs — Project Dashboard -
- -

API Documentation

-

Choose a renderer. ReDoc is visually polished; Stoplight gives a modern interactive portal similar to Knife4j.

- -
-
-

ReDoc — Readable & clean

-

Great for well-structured API reference. Non-interactive but very pretty.

-

Open ReDoc →

-
- -
-

Stoplight Elements — Interactive

-

Modern UI with playground/try-it-out support and a Knife4j-like feel.

-

Open Stoplight →

-
- -
-

RapiDoc — Lightweight

-

Existing lightweight renderer included for quick inspection.

-

Open RapiDoc →

-
-
-
- - - `) - }) - - // --- RapiDoc route (moved from /docs to /docs/rapidoc) --- - app.get('/docs/rapidoc', (_, reply) => { - reply.type('text/html').send(` - - - - - - - - - - - `) - }) - - // --- API Documentation with ReDoc (alternative nicer UI) --- - // ReDoc gives a clean, modern single-page OpenAPI rendering similar to Knife4j's look. - app.get('/docs/redoc', (_, reply) => { - reply.type('text/html').send(` - - - - - - API Docs — ReDoc - - - - - -
+ + - - - `) - }) - - // --- Stoplight Elements (interactive, Knife4j-like feel) --- - // Uses Stoplight Elements Web Components from CDN to render a modern interactive portal. - app.get('/docs/stoplight', (_, reply) => { - reply.type('text/html').send(` - - - - - - API Docs — Stoplight - - - - - - -
- stoplight -

Interactive API Docs

-
-
- - - - -
+ \` + } + + var apiReference = document.getElementById('api-reference') + apiReference.dataset.configuration = JSON.stringify(configuration) + + `) @@ -242,7 +178,6 @@ async function bootstrap() { app.log.error(error) reply.status(500).send({ error: 'Internal Server Error' }) }) - return app }