Files
pbakaus_impeccable/api/commands.js
T
Paul BakausandClaude Opus 4.5 73a3367e0a Fix: Use standard Vercel serverless function format (req, res)
Response.json() is for Edge Functions, not Node.js serverless functions.
Switched all API handlers to use res.status().json() format which is
the standard for Vercel Node.js functions.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 15:00:08 -08:00

43 lines
1.3 KiB
JavaScript

import { readdirSync, readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const PROJECT_ROOT = join(__dirname, "..");
export default function handler(req, res) {
try {
const sourceDir = join(PROJECT_ROOT, "source");
const commandsDir = join(sourceDir, "commands");
const files = readdirSync(commandsDir);
const commands = [];
for (const file of files) {
if (file.endsWith(".md")) {
const content = readFileSync(join(commandsDir, file), "utf-8");
const frontmatterMatch = content.match(/^---\n([\s\S]+?)\n---/);
if (frontmatterMatch) {
const frontmatter = frontmatterMatch[1];
const nameMatch = frontmatter.match(/name:\s*(.+)/);
const descMatch = frontmatter.match(/description:\s*(.+)/);
commands.push({
id: file.replace(".md", ""),
name: nameMatch?.[1]?.trim() || file.replace(".md", ""),
description: descMatch?.[1]?.trim() || "No description available",
});
}
}
}
res.status(200).json(commands);
} catch (error) {
console.error("Error in /api/commands:", error);
res.status(500).json({ error: error.message, stack: error.stack });
}
}