- Updated the documentation API endpoints to dynamically set the documentation directory based on the NODE_ENV variable, improving compatibility between development and production environments. - Enhanced error handling for file retrieval to ensure proper responses when files are not found or invalid. - Standardized import statements for consistency across the documentation files.
20 lines
592 B
JavaScript
20 lines
592 B
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { file } = event.context.params;
|
|
let docsDir = "";
|
|
if (process.env.NODE_ENV === "development") {
|
|
docsDir = path.resolve(process.cwd(), "content/documentation");
|
|
} else {
|
|
docsDir = path.resolve(process.cwd(), "../content/documentation");
|
|
}
|
|
|
|
const filePath = path.join(docsDir, file);
|
|
if (!file.endsWith(".md") || !fs.existsSync(filePath)) {
|
|
return { error: "File not found" };
|
|
}
|
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
return { content };
|
|
});
|