UNPKG

morphbox

Version:

Docker-based AI sandbox for development with Claude integration

45 lines (42 loc) 1.33 kB
import { e as error, j as json } from './index-3BbzJtgI.js'; import { promises } from 'fs'; import path from 'path'; import { W as WORKSPACE_DIR } from './workspace-CcQOwpY7.js'; import 'child_process'; import 'util'; function validatePath(requestPath) { const normalized = path.normalize(path.join(WORKSPACE_DIR, requestPath)); if (!normalized.startsWith(WORKSPACE_DIR)) { throw error(403, "Access denied: Path outside workspace directory"); } return normalized; } const GET = async ({ url }) => { try { const filePath = url.searchParams.get("path"); if (!filePath) { throw error(400, "Path is required"); } const fullPath = validatePath(filePath); const stats = await promises.stat(fullPath); if (stats.isDirectory()) { throw error(400, "Path is a directory, not a file"); } const content = await promises.readFile(fullPath, "utf-8"); return json({ path: filePath, content, size: stats.size, modified: stats.mtime.toISOString() }); } catch (err) { if (err instanceof Response) throw err; if (err.code === "ENOENT") { throw error(404, "File not found"); } console.error("Error reading file:", err); throw error(500, "Failed to read file"); } }; export { GET }; //# sourceMappingURL=_server.ts-Dv3iYDOA.js.map