Skip to content

Commit

Permalink
fix: 修复 mock api 跨域问题 (#6797)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed May 6, 2023
1 parent 49cf0f0 commit b80b70b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mock/cfc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ function mockResponse(event, context, callback) {
function createHeaders(headers) {
let referer = '';

if (/^(https?\:\/\/[^:\/]+(?:\:\d+)?\/)/i.test(headers['referer'])) {
if (/^(https?\:\/\/[^:\/]+(?:\:\d+)?\/)/i.test(headers['Referer'])) {
referer = RegExp.$1.replace(/\/$/, '');
}

return {
'Content-Type': 'Application/json',
'Access-Control-Allow-Headers': 'x-requested-with,content-type',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS,HEAD',
'Access-Control-Allow-Origin': referer ? `${referer}` : '*'
'Access-Control-Allow-Origin': referer ? `${referer}` : '*',
'Access-Control-Allow-Credentials': 'true'
};
}

0 comments on commit b80b70b

Please sign in to comment.