Skip to content

Commit cc092bd

Browse files
committed
chore: config file to storage
1 parent 2865104 commit cc092bd

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Diff for: nuxt.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ export default defineNuxtConfig({
3939
colorMode: {
4040
classSuffix: '',
4141
},
42+
nitro: {
43+
storage: {
44+
data: {
45+
driver: 'fs',
46+
base: './data'
47+
}
48+
}
49+
}
4250
})

Diff for: server/plugins/1.config-loader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default defineNitroPlugin(async (nitroApp) => {
2-
const localConfig = getLocalConfig()
2+
const localConfig = await getLocalConfig()
33

44
if (!localConfig) {
55
console.error('Config not loaded!')

Diff for: server/utils/config.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'node:fs'
21
import crypto from 'node:crypto'
32
import yaml from 'yaml'
43
import type { BaseService, Config } from '~/types'
@@ -12,13 +11,17 @@ function determineServiceId(items: draftService[]): BaseService[] {
1211
}))
1312
}
1413

15-
export function getLocalConfig(): Config | null {
14+
export async function getLocalConfig(): Promise<Config | null> {
15+
const storage = useStorage('data')
16+
const file = 'config.yml'
17+
1618
try {
17-
if (!fs.existsSync('assets/config.yaml')) {
19+
if (!await storage.hasItem(file)) {
1820
return null
1921
}
2022

21-
const config = yaml.parse(fs.readFileSync('assets/config.yaml', 'utf8')) || {}
23+
const raw = await storage.getItem<string>(file)
24+
const config = yaml.parse(raw || '') || {}
2225
const services: Config['services'] = []
2326

2427
if (Array.isArray(config.services)) {

0 commit comments

Comments
 (0)