Fetch config via api and move config to data directory

This commit is contained in:
DerTyp7
2025-10-09 18:30:09 +02:00
parent c4529ef601
commit a45e379dd1
5 changed files with 79 additions and 101 deletions
+15
View File
@@ -0,0 +1,15 @@
import { configPath, configTemplate } from '@/const/api';
import fs from 'fs/promises';
import { NextRequest, NextResponse } from 'next/server';
export async function GET(request: NextRequest) {
try {
const fileBuffer = await fs.readFile(configPath, 'utf8');
const config = JSON.parse(fileBuffer);
console.log(config);
return NextResponse.json(config, { status: 200 });
} catch {
await fs.writeFile(configPath, JSON.stringify(configTemplate, null, 2));
return NextResponse.json(configTemplate, { status: 201 });
}
}