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
JavaScript
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);
});
};