24 lines
672 B
TypeScript
24 lines
672 B
TypeScript
'server'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
import { AppConfig, defaultConfig } from '@/config/AppConfig'
|
|
|
|
const configFilePath = path.join(process.cwd(), 'runtimeConfig.json')
|
|
|
|
function loadConfig(): AppConfig {
|
|
let config = defaultConfig
|
|
|
|
if (fs.existsSync(configFilePath)) {
|
|
const raw = fs.readFileSync(configFilePath, 'utf-8')
|
|
const parsed = JSON.parse(raw)
|
|
config = { ...defaultConfig, ...parsed }
|
|
} else {
|
|
fs.mkdirSync(path.dirname(configFilePath), { recursive: true })
|
|
}
|
|
fs.writeFileSync(configFilePath, JSON.stringify(defaultConfig, null, 4))
|
|
|
|
return config
|
|
}
|
|
|
|
export const appConfig = loadConfig()
|