Fetch config via api and move config to data directory
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user