diff --git a/src/app/api/admin/config/route.ts b/src/app/api/admin/config/route.ts index 7ffbb68..3b5c20c 100644 --- a/src/app/api/admin/config/route.ts +++ b/src/app/api/admin/config/route.ts @@ -1,7 +1,6 @@ import { NextRequest, NextResponse } from 'next/server' import { readFile, writeFile } from 'node:fs/promises' import path from 'node:path' -import config from '@/config/config.json' export const runtime = 'nodejs' @@ -13,17 +12,22 @@ type ConfigData = { competitionName: string } +async function getConfig(): Promise { + const configPath = path.join(process.cwd(), 'src', 'config', 'config.json') + const content = await readFile(configPath, 'utf8') + return JSON.parse(content) +} + export async function GET(req: NextRequest) { const password = req.headers.get('x-admin-password') || '' + const config = await getConfig() if (password !== config.adminPassword) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } try { - const configPath = path.join(process.cwd(), 'src', 'config', 'config.json') - const content = await readFile(configPath, 'utf8') - const data = JSON.parse(content) - return NextResponse.json(data) + const config = await getConfig() + return NextResponse.json(config) } catch (e: any) { return NextResponse.json({ error: 'Failed to read config' }, { status: 500 }) } @@ -31,6 +35,7 @@ export async function GET(req: NextRequest) { export async function POST(req: NextRequest) { const password = req.headers.get('x-admin-password') || '' + const config = await getConfig() if (password !== config.adminPassword) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) }