add 配置读取写入

This commit is contained in:
2023-08-01 13:02:12 +08:00
parent c4f88a5368
commit a0d7b9b17f
6 changed files with 72 additions and 4 deletions

32
router/config.js Normal file
View File

@@ -0,0 +1,32 @@
const Router = require("koa-router")
const config = require("../util/config/config")
const router = new Router({
prefix: "/config"
})
/**
* 获取配置文件接口
*/
router.get('/getConfig', async (ctx) => {
let json = config.getConfig();
const b = json === '{}'
return {
code: b ? -1 : 0,
msg: b ? 'ok' : "error",
data: json
}
})
/**
* 设置配置文件接口
*/
router.get('/setConfig', async (ctx) => {
let b = config.setConfig(ctx.data);
return {
code: b ? -1 : 0,
msg: b ? 'ok' : "error",
data: null
}
})
module.exports = router