morphbox
Version:
Docker-based AI sandbox for development with Claude integration
36 lines (33 loc) • 1.16 kB
JavaScript
import { t as text } from './index-3BbzJtgI.js';
import { readFile } from 'fs/promises';
import { normalize } from 'path';
import { homedir } from 'os';
const PANELS_DIR = normalize(`${homedir()}/morphbox/panels`);
const GET = async ({ url }) => {
let fullPath = "";
try {
const path = url.searchParams.get("path");
if (!path) {
return text("Path parameter is required", { status: 400 });
}
if (isAbsolute(path)) {
fullPath = normalize(path);
if (!fullPath.startsWith(PANELS_DIR)) {
return text("Invalid path", { status: 403 });
}
} else {
fullPath = normalize(`${PANELS_DIR}/${path}`);
}
const content = await readFile(fullPath, "utf-8");
return text(content);
} catch (error) {
console.error("Failed to load custom panel:", error);
const errorMessage = error instanceof Error ? error.message : "Unknown error";
if (error.code === "ENOENT") {
return text(`Panel file not found: ${fullPath}`, { status: 404 });
}
return text(`Failed to load panel: ${errorMessage}`, { status: 500 });
}
};
export { GET };
//# sourceMappingURL=_server.ts-CWds_QVF.js.map