diff --git a/src/controllers/open/jump.js b/src/controllers/open/jump.js index bce6e95..5a8a953 100644 --- a/src/controllers/open/jump.js +++ b/src/controllers/open/jump.js @@ -6,8 +6,19 @@ import GameJump from '../../models/admin/GameJump' import cors from 'cors' const router = new Router() +const whitelist = ['https://promotion.kingsome.cn', 'https://promotion-test.kingsome.cn', 'http://promotion.kingsome.cn','http://promotion-test.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('/', cors(), async (req, res, next) => { +router.get('/', cors(corsOptions), async (req, res, next) => { try { const query = req.query const currentPage = parseInt(query.currentPage) @@ -41,7 +52,7 @@ router.get('/', cors(), async (req, res, next) => { }) // 添加关联游戏 -router.post('/', cors(), async (req, res, next) => { +router.post('/', cors(corsOptions), async (req, res, next) => { try { const body = req.body const game_id = body.game_id @@ -82,7 +93,7 @@ router.post('/', cors(), async (req, res, next) => { } }) // 修改关联游戏 -router.put('/', cors(), async (req, res, next) => { +router.put('/', cors(corsOptions), async (req, res, next) => { try { const body = req.body const jump_id = body._id @@ -115,7 +126,7 @@ router.put('/', cors(), async (req, res, next) => { }) // 删除关联游戏 -router.delete('/', cors(), async (req, res, next) => { +router.delete('/', cors(corsOptions), async (req, res, next) => { try { const body = req.body const jump_id = body.jump_id