新增获取服务端配置接口

This commit is contained in:
yulixing 2019-10-22 14:57:46 +08:00
parent 00ffdaa4c2
commit 6fea671362
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,53 @@
/* 推广系统-广告专用 */
import {Router} from 'express'
import config from '../../../config/config'
import redis from 'redis'
import cors from 'cors'
const router = new Router()
const whitelist = ['http://promotion.kingsome.cn']
const corsOptions = {
origin: function(origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
}
// 获取 中英文对照表
router.get('/all', cors(), async (req, res, next) => {
try {
const query = req.query
const key = `server_config:${query.gameid}:${query.channelid}`
const keyName = query.key
const client = redis.createClient({
host: config.redisPublish.host,
port: config.redisPublish.port,
password: config.redisPublish.password,
})
let records = await client.getAsync(key)
records = JSON.parse(records) || []
let result = records
if (keyName) {
result = records.filter(item => {
return item.key === keyName
})
result = result[0] ? JSON.parse(result[0].value) : {}
}
res.send({
errcode: 0,
result,
})
} catch (err) {
next(err)
}
})
export default router

View File

@ -7,6 +7,7 @@ import gamesRouter from './games'
import adUidRouter from './ad-uid'
import jumpRouter from './jump'
import gameListRouter from './game-list'
import cfgRouter from './cfg'
const router = new Router()
@ -16,6 +17,7 @@ router.use('/games', gamesRouter)
router.use('/ad-uid', adUidRouter)
router.use('/jump', jumpRouter)
router.use('/game-list', gameListRouter)
router.use('/cfg',cfgRouter)
export default router