import {NextResponse} from "next/server"; import fs from "fs"; import path from "path"; let writeLock: boolean = false; export async function GET() { const configPath = process.env.CONFIG_PATH || "./config.json"; const absolutePath = path.resolve(configPath); if (!fs.existsSync(absolutePath)) { return NextResponse.json({error: "Config file not found"}, {status: 404}); } const fileContent = fs.readFileSync(absolutePath, "utf-8"); const config = JSON.parse(fileContent); return NextResponse.json(config); } // post function for updating the config export async function POST({body}) { if (writeLock) { return NextResponse.json({error: "Write lock is active"}, {status: 400}); } writeLock = true; try { const configPath = process.env.CONFIG_PATH || "./config.json"; const absolutePath = path.resolve(configPath); fs.writeFileSync(absolutePath, JSON.stringify(body, null, 2)); return NextResponse.json({success: true}); } catch (e) { return NextResponse.json({error: e.message}, {status: 500}); } finally { writeLock = false; } }