fix: 修复 mock api 跨域问题 (#6797)

This commit is contained in:
liaoxuezhi 2023-05-06 13:02:50 +08:00 committed by GitHub
parent 49cf0f09dd
commit b80b70b1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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'
};
}