initial commit
This commit is contained in:
24
server/src/routes/schema.ts
Normal file
24
server/src/routes/schema.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// routes/schema.ts
|
||||
import { json } from "../index";
|
||||
import { writeFileSync, readFileSync, existsSync, mkdirSync } from "fs";
|
||||
import { dirname } from "path";
|
||||
|
||||
const SCHEMA_PATH = Bun.env.SCHEMA_PATH ?? "./config/schema.json";
|
||||
|
||||
export const schemaHandler = {
|
||||
async post(req: Request) {
|
||||
try {
|
||||
const text = await req.text();
|
||||
JSON.parse(text); // validate JSON
|
||||
mkdirSync(dirname(SCHEMA_PATH), { recursive: true });
|
||||
writeFileSync(SCHEMA_PATH, text, "utf8");
|
||||
return json({ ok: true });
|
||||
} catch (e: any) { return json({ error: e.message }, 400); }
|
||||
},
|
||||
async get() {
|
||||
if (!existsSync(SCHEMA_PATH)) return json({ error: "No schema yet" }, 404);
|
||||
return new Response(readFileSync(SCHEMA_PATH, "utf8"), {
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user