|
|
const _ = require('lodash');
|
|
|
|
|
|
/**
|
|
|
* 异步请求跨域处理
|
|
|
*/
|
|
|
module.exports = (req, res, next) => {
|
|
|
let allowOrigin = _.get(req, 'headers.origin', null) ?
|
|
|
req.headers.origin : req.protocol + '://' + req.headers.host;
|
|
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
|
|
|
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
|
|
|
|
return next();
|
|
|
}; |
...
|
...
|
|