Yuzuo a gateway service node, the transmission of information by doing cookie, select the frame koa2, where a simple recording process and cross-domain cookie acquisition.
First of all: to solve the problem of cross-domain, using koa2-cros to deal with cross-domain issues like the back-end processing, with no front-end melon.
const cors = require('koa2-cros') app.use(cors({ origin: '*' }))
Second: the solution is passed across domains cookie problem now is not the default browser requests with a cookie, the cookie is required to bring add configuration parameters, native fetch method to add credentials: 'include' parameters, as follows:
fetch('htp://192.168.210.151:3002/proxy', { credentials: 'include', })
Backend add credentails: to true
const cors = require('koa2-cros') app.use(cors({ origin: '*', credentails: true, }))
Then a new problem arises, the browser requesting the following questions arise
Means that the Access-Control-Allow-Origin: '*' and credentials: 'include' can not coexist, where the required back-end request header Access-Control-Allow-Origin: '*' in the '*' into the transmission request origin like, if rough point, then directly into the following
the require CORS = const ( 'koa2-Cros' ) app.use (CORS ({ Origin: (CTX) => { const Origin = ctx.headers.origin // make the actual production rule configured according to the specific circumstances return Origin } } ))
Response Headers and then compare the client to get the following
In the end, though still occur Provisional headers are shown this warning, but you can also get a front-end data, and the back-end can also get a cookie.
Other browsers do not appear in this Provisional headers are shown a warning, so this should only be a warning of chrome.