Add public API documentation endpoint

Features:
- New GET /docs/api endpoint to retrieve full API documentation
- Returns API.md content as JSON with markdown format
- No authentication required (public endpoint)
- Includes lastUpdated timestamp
- 26,754 characters of complete documentation

Response format:
{
  "success": true,
  "documentation": "<full markdown content>",
  "format": "markdown",
  "lastUpdated": "2025-12-08T12:12:38.942Z"
}

Use case:
- Fetch documentation programmatically
- Display in external applications
- Copy-paste into AI assistants (Claude, ChatGPT)
- Auto-generate API clients

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
debian.StillHammer 2025-12-08 12:38:15 +00:00
parent ea4c49b781
commit c1837eca1d

View File

@ -101,7 +101,7 @@ app.use((req, res, next) => {
// API Authentication Middleware
const authenticate = (req, res, next) => {
// Skip authentication for public endpoints
const publicEndpoints = ['/health', '/api'];
const publicEndpoints = ['/health', '/api', '/docs/api'];
// Allow public download endpoint
if (publicEndpoints.includes(req.path) || req.path.startsWith('/public/download/')) {
return next();
@ -174,6 +174,39 @@ app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
/**
* GET /docs/api
* Get complete API documentation (markdown)
*/
app.get('/docs/api', (req, res) => {
try {
const docPath = path.join(__dirname, '../docs/API.md');
if (!fs.existsSync(docPath)) {
return res.status(404).json({
error: 'Documentation not found',
message: 'API documentation file does not exist'
});
}
const docContent = fs.readFileSync(docPath, 'utf-8');
// Return as JSON with markdown content
res.json({
success: true,
documentation: docContent,
format: 'markdown',
lastUpdated: fs.statSync(docPath).mtime
});
} catch (error) {
console.error(`[API Docs] Error: ${error.message}`);
res.status(500).json({
error: 'Failed to retrieve documentation',
message: error.message
});
}
});
/**
* GET /public/download/:filename
* Public endpoint to download files without authentication
@ -1471,6 +1504,7 @@ app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
console.log('\nEndpoints:');
console.log(' GET /health - Health check');
console.log(' GET /docs/api - API documentation (no auth)');
console.log(' GET /public/download/:filename - Public file download (no auth)');
console.log(' GET /info?url= - Get video/playlist info');
console.log(' POST /download - Download as MP3');