mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复 mock api 跨域问题 (#6797)
This commit is contained in:
parent
49cf0f09dd
commit
b80b70b1ef
@ -56,7 +56,7 @@ 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(/\/$/, '');
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ function createHeaders(headers) {
|
||||
'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'
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user