abler-api 0.1.77 → 0.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/pp-util.js +6 -11
- package/package.json +1 -1
package/dist/cjs/pp-util.js
CHANGED
|
@@ -1324,29 +1324,21 @@ class apiUtil$2 {
|
|
|
1324
1324
|
value
|
|
1325
1325
|
};
|
|
1326
1326
|
}
|
|
1327
|
-
static
|
|
1327
|
+
static isOriginAllowed(origin) {
|
|
1328
1328
|
if (!origin || appSetting.corsOrigin === "*") {
|
|
1329
|
-
|
|
1330
|
-
return;
|
|
1329
|
+
return true;
|
|
1331
1330
|
}
|
|
1332
1331
|
origin = origin.toLowerCase();
|
|
1333
|
-
let isAllowed = false;
|
|
1334
1332
|
let allowedOrigins = appSetting.corsOrigin;
|
|
1335
1333
|
if (Array.isArray(allowedOrigins)) {
|
|
1336
1334
|
allowedOrigins = appSetting.corsOrigin.map(o => o.toLowerCase());
|
|
1337
1335
|
// 检查请求的origin是否在允许的列表中,支持简单的通配符匹配
|
|
1338
|
-
|
|
1336
|
+
return allowedOrigins.some(allowedOrigin => {
|
|
1339
1337
|
return allowed(allowedOrigin);
|
|
1340
1338
|
});
|
|
1341
1339
|
} else {
|
|
1342
1340
|
return allowed(allowedOrigins.toLowerCase());
|
|
1343
1341
|
}
|
|
1344
|
-
if (isAllowed) {
|
|
1345
|
-
callback(null, true);
|
|
1346
|
-
} else {
|
|
1347
|
-
// callback(new Error('Not allowed by CORS')); // 拒绝CORS请求
|
|
1348
|
-
callback(null, false);
|
|
1349
|
-
}
|
|
1350
1342
|
function allowed(allowedOrigin) {
|
|
1351
1343
|
if (allowedOrigin.includes("*")) {
|
|
1352
1344
|
const regex = new RegExp("^" + allowedOrigin.replace(/\*/g, ".*") + "$");
|
|
@@ -1355,6 +1347,9 @@ class apiUtil$2 {
|
|
|
1355
1347
|
return allowedOrigin === origin;
|
|
1356
1348
|
}
|
|
1357
1349
|
}
|
|
1350
|
+
static corsCheckOrigin(origin, callback) {
|
|
1351
|
+
callback(null, apiUtil$2.isOriginAllowed(origin));
|
|
1352
|
+
}
|
|
1358
1353
|
|
|
1359
1354
|
//#endregion
|
|
1360
1355
|
|