@react-pakistan/util-functions 1.22.32 → 1.22.34
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/api/cors/index.d.ts +1 -0
- package/api/cors/index.js +26 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCorsHeaders: (origin: string) => unknown;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCorsHeaders = void 0;
|
|
4
|
+
const getCorsHeaders = (origin) => {
|
|
5
|
+
// Default options
|
|
6
|
+
const headers = {
|
|
7
|
+
'Access-Control-Allow-Methods': `${process.env.ALLOWED_METHODS}`,
|
|
8
|
+
'Access-Control-Allow-Headers': `${process.env.ALLOWED_HEADERS}`,
|
|
9
|
+
'Access-Control-Allow-Origin': `${process.env.ALLOWED_ORIGIN}`,
|
|
10
|
+
};
|
|
11
|
+
// If no allowed origin is set to default server origin
|
|
12
|
+
if (!process.env.ALLOWED_ORIGIN || !origin)
|
|
13
|
+
return headers;
|
|
14
|
+
// If allowed origin is set, check if origin is in allowed origins
|
|
15
|
+
const allowedOrigins = process.env.ALLOWED_ORIGIN.split(',');
|
|
16
|
+
// Validate server origin
|
|
17
|
+
if (allowedOrigins.includes('*')) {
|
|
18
|
+
headers['Access-Control-Allow-Origin'] = '*';
|
|
19
|
+
}
|
|
20
|
+
else if (allowedOrigins.includes(origin)) {
|
|
21
|
+
headers['Access-Control-Allow-Origin'] = origin;
|
|
22
|
+
}
|
|
23
|
+
// Return result
|
|
24
|
+
return headers;
|
|
25
|
+
};
|
|
26
|
+
exports.getCorsHeaders = getCorsHeaders;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api/stellar-solutions/customer"), exports);
|
|
18
|
+
__exportStar(require("./api/cors"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
19
20
|
__exportStar(require("./general"), exports);
|
|
20
21
|
__exportStar(require("./hooks"), exports);
|