Showing
1 changed file
with
14 additions
and
0 deletions
doraemon/middleware/cors.js
0 → 100644
1 | +const _ = require('lodash'); | ||
2 | + | ||
3 | +/** | ||
4 | + * 异步请求跨域处理 | ||
5 | + */ | ||
6 | +module.exports = (req, res, next) => { | ||
7 | + let allowOrigin = _.get(req, 'headers.origin', null) ? | ||
8 | + req.headers.origin : req.protocol + '://' + req.headers.host; | ||
9 | + | ||
10 | + res.setHeader('Access-Control-Allow-Origin', allowOrigin); | ||
11 | + res.setHeader('Access-Control-Allow-Credentials', 'true'); | ||
12 | + | ||
13 | + return next(); | ||
14 | +}; |
-
Please register or login to post a comment