diff --git a/src/controllers/open/cfg.js b/src/controllers/open/cfg.js new file mode 100644 index 0000000..712bb6a --- /dev/null +++ b/src/controllers/open/cfg.js @@ -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 diff --git a/src/controllers/open/index.js b/src/controllers/open/index.js index f048316..e9bb5dc 100644 --- a/src/controllers/open/index.js +++ b/src/controllers/open/index.js @@ -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