UNPKG

api-scout

Version:

๐Ÿ” Automatically scout, discover and generate beautiful interactive API documentation from your codebase. Supports Express.js, NestJS, FastAPI, Spring Boot with interactive testing and security analysis.

45 lines (38 loc) โ€ข 1.59 kB
const express = require('express'); const path = require('path'); const chalk = require('chalk'); const fs = require('fs-extra'); module.exports = async function serveCommand(options) { const docsPath = path.resolve(options.docs); const port = parseInt(options.port) || 3000; // Check if docs directory exists if (!await fs.pathExists(docsPath)) { console.error(chalk.red('โŒ Documentation directory not found!')); console.log(chalk.yellow('๐Ÿ’ก Run "api-scout generate" first to create documentation.')); process.exit(1); } const app = express(); // Serve static files app.use(express.static(docsPath)); // SPA fallback for client-side routing app.get('*', (req, res) => { const indexPath = path.join(docsPath, 'index.html'); if (fs.existsSync(indexPath)) { res.sendFile(indexPath); } else { res.status(404).send('Documentation not found. Run "api-scout generate" first.'); } }); app.listen(port, () => { console.log(chalk.green('๐Ÿš€ API Scout documentation server started!')); console.log(chalk.cyan(`๐Ÿ“– Open your browser: ${chalk.yellow(`http://localhost:${port}`)}`)); console.log(chalk.gray(`๐Ÿ“ Serving from: ${docsPath}`)); console.log(chalk.gray('\n๐Ÿ’ก Press Ctrl+C to stop the server')); console.log(chalk.gray('๐Ÿงช Use the interactive tester to try your APIs!')); }); // Graceful shutdown process.on('SIGINT', () => { console.log(chalk.yellow('\n๐Ÿ‘‹ Shutting down API Scout server...')); process.exit(0); }); };