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 { NextRequest, NextResponse } from 'next/server'
|
||||||
import { readFile, writeFile } from 'node:fs/promises'
|
import { readFile, writeFile } from 'node:fs/promises'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import config from '@/config/config.json'
|
|
||||||
|
|
||||||
export const runtime = 'nodejs'
|
export const runtime = 'nodejs'
|
||||||
|
|
||||||
|
|
@ -13,17 +12,22 @@ type ConfigData = {
|
||||||
competitionName: string
|
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) {
|
export async function GET(req: NextRequest) {
|
||||||
const password = req.headers.get('x-admin-password') || ''
|
const password = req.headers.get('x-admin-password') || ''
|
||||||
|
const config = await getConfig()
|
||||||
if (password !== config.adminPassword) {
|
if (password !== config.adminPassword) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const configPath = path.join(process.cwd(), 'src', 'config', 'config.json')
|
const config = await getConfig()
|
||||||
const content = await readFile(configPath, 'utf8')
|
return NextResponse.json(config)
|
||||||
const data = JSON.parse(content)
|
|
||||||
return NextResponse.json(data)
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return NextResponse.json({ error: 'Failed to read config' }, { status: 500 })
|
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) {
|
export async function POST(req: NextRequest) {
|
||||||
const password = req.headers.get('x-admin-password') || ''
|
const password = req.headers.get('x-admin-password') || ''
|
||||||
|
const config = await getConfig()
|
||||||
if (password !== config.adminPassword) {
|
if (password !== config.adminPassword) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue