diff --git a/src/server.js b/src/server.js index 557dd14..f012e7d 100644 --- a/src/server.js +++ b/src/server.js @@ -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');