koa2 allow cross-domain

In the development environment, it is easy to encounter this problem, cross-domain problems have different port access.

problem:

With the rear end of koa2, start to develop port 3000

Vue port front-end accounts for 8080, cross-domain problems encountered.

koa2-cors module

The official address :( https://github.com/zadzbw/koa2-cors )

1, the installation koa2-cors
yarn add koa2-cors
2, is introduced and configured middleware koa2-cors
var Koa = require('koa');
var cors = require('koa2-cors');
var app = new Koa();
app.use(cors());

Step two direct configuration OK.

 

http://www.webliu.cn/koa2/

Guess you like

Origin www.cnblogs.com/shaozhu520/p/11312984.html