config update
This commit is contained in:
parent
b669775a29
commit
0677b13902
1 changed files with 10 additions and 5 deletions
|
|
@ -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<ConfigData> {
|
||||
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 })
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue