@bool-ts/core 1.0.6 → 1.0.8
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 +7 -13
- package/package.json +1 -1
- package/src/hooks/factory.ts +7 -5
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,16 @@ 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) {
|
|
123
|
-
return res.status(403).json({
|
|
124
|
-
["httpCode"]: 403,
|
|
125
|
-
["data"]: "CORS Origin - Not found."
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
122
|
if (!allowOrigins.includes("*")) {
|
|
129
|
-
if (!allowOrigins.includes(req.headers.origin)) {
|
|
123
|
+
if (!allowOrigins.includes(req.headers.origin || "*")) {
|
|
130
124
|
return res.status(403).json({
|
|
131
125
|
["httpCode"]: 403,
|
|
132
126
|
["data"]: "Invalid origin."
|
|
133
127
|
});
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
|
-
res.header("Access-Control-Allow-Origin", req.headers.origin);
|
|
130
|
+
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
|
|
137
131
|
res.header("Access-Control-Allow-Headers", "*");
|
|
138
132
|
res.header("Access-Control-Allow-Credentials", "true");
|
|
139
133
|
res.header("Access-Control-Allow-Methods", allowMethods.join(", "));
|
package/package.json
CHANGED
package/src/hooks/factory.ts
CHANGED
|
@@ -149,11 +149,13 @@ export const BoolFactory = (
|
|
|
149
149
|
);
|
|
150
150
|
|
|
151
151
|
app.use((req: Request, res: Response, next: NextFunction) => {
|
|
152
|
-
if (!allowOrigins.includes(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
if (!allowOrigins.includes("*")) {
|
|
153
|
+
if (!allowOrigins.includes(req.headers.origin || "*")) {
|
|
154
|
+
return res.status(403).json({
|
|
155
|
+
["httpCode"]: 403,
|
|
156
|
+
["data"]: "Invalid origin."
|
|
157
|
+
});
|
|
158
|
+
}
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
|