@bool-ts/core 1.0.6 → 1.0.7
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/hooks/factory.js +8 -16
- package/package.json +1 -1
package/dist/hooks/factory.js
CHANGED
|
@@ -52,6 +52,11 @@ export const BoolFactory = (target) => {
|
|
|
52
52
|
}
|
|
53
53
|
const metadata = Reflect.getOwnMetadata(moduleKey, target);
|
|
54
54
|
const routers = !metadata?.controllers ? [] : metadata.controllers.map(controllerConstructor => controllerCreator(controllerConstructor));
|
|
55
|
+
const allowOrigins = !metadata?.allowOrigins ?
|
|
56
|
+
["*"] : typeof metadata.allowOrigins !== "string" ?
|
|
57
|
+
metadata.allowOrigins : [metadata.allowOrigins];
|
|
58
|
+
const allowMethods = !metadata?.allowMethods ?
|
|
59
|
+
["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"] : metadata.allowMethods;
|
|
55
60
|
const app = ExpressApp();
|
|
56
61
|
const configs = Object.freeze({
|
|
57
62
|
allowLogsMethods: [
|
|
@@ -113,27 +118,14 @@ export const BoolFactory = (target) => {
|
|
|
113
118
|
const convertedTime = `${Math.round((time + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
|
|
114
119
|
console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
|
|
115
120
|
}));
|
|
116
|
-
const allowOrigins = !metadata?.allowOrigins ?
|
|
117
|
-
["*"] : typeof metadata.allowOrigins !== "string" ?
|
|
118
|
-
metadata.allowOrigins : [metadata.allowOrigins];
|
|
119
|
-
const allowMethods = !metadata?.allowMethods ?
|
|
120
|
-
["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"] : metadata.allowMethods;
|
|
121
121
|
app.use((req, res, next) => {
|
|
122
|
-
if (!req.headers.origin) {
|
|
122
|
+
if (!allowOrigins.includes(req.headers.origin || "*")) {
|
|
123
123
|
return res.status(403).json({
|
|
124
124
|
["httpCode"]: 403,
|
|
125
|
-
["data"]: "
|
|
125
|
+
["data"]: "Invalid origin."
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
if (!allowOrigins.includes(req.headers.origin)) {
|
|
130
|
-
return res.status(403).json({
|
|
131
|
-
["httpCode"]: 403,
|
|
132
|
-
["data"]: "Invalid origin."
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
res.header("Access-Control-Allow-Origin", req.headers.origin);
|
|
128
|
+
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
|
|
137
129
|
res.header("Access-Control-Allow-Headers", "*");
|
|
138
130
|
res.header("Access-Control-Allow-Credentials", "true");
|
|
139
131
|
res.header("Access-Control-Allow-Methods", allowMethods.join(", "));
|