add 配置读取写入
This commit is contained in:
32
router/config.js
Normal file
32
router/config.js
Normal 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
|
||||
Reference in New Issue
Block a user