From 3a07dfbacfbd6a460ddd5a0d0860c09a20658c1d Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 17 Aug 2018 22:52:41 +0800 Subject: [PATCH] add cors setting --- app.js | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/app.js b/app.js index 4ead8a8..c8902f2 100644 --- a/app.js +++ b/app.js @@ -2,10 +2,16 @@ const config = require('./config') const Koa = require('koa') const koaLogger = require('koa-logger') const koaSession = require('koa-session2') +const cors = require('kcors') const router = require('./route') const app = new Koa() app.use(koaLogger()) +app.use(cors({ + origin: (c) => { + return c.get('Origin') + } +})) app.use(koaSession()) app.use(router.allowedMethods()) app.use(router.routes()) diff --git a/package.json b/package.json index 51b3f70..86d03ab 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dotenv": "^6.0.0", "gm": "^1.23.1", "ioredis": "^3.2.2", + "kcors": "^2.2.2", "koa": "^2.5.1", "koa-body": "^4.0.3", "koa-logger": "^3.2.0",