@bool-ts/core 1.0.5 → 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.
@@ -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"]: "CORS Origin - Not found."
125
+ ["data"]: "Invalid origin."
126
126
  });
127
127
  }
128
- if (!allowOrigins.includes("*")) {
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(", "));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -70,6 +70,11 @@ export const BoolFactory = (
70
70
 
71
71
  const metadata = Reflect.getOwnMetadata(moduleKey, target) as TModuleOptions;
72
72
  const routers = !metadata?.controllers ? [] : metadata.controllers.map(controllerConstructor => controllerCreator(controllerConstructor));
73
+ const allowOrigins = !metadata?.allowOrigins ?
74
+ ["*"] : typeof metadata.allowOrigins !== "string" ?
75
+ metadata.allowOrigins : [metadata.allowOrigins];
76
+ const allowMethods = !metadata?.allowMethods ?
77
+ ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"] : metadata.allowMethods;
73
78
  const app = ExpressApp();
74
79
  const configs = Object.freeze({
75
80
  allowLogsMethods: [
@@ -143,31 +148,15 @@ export const BoolFactory = (
143
148
  })
144
149
  );
145
150
 
146
- const allowOrigins = !metadata?.allowOrigins ?
147
- ["*"] : typeof metadata.allowOrigins !== "string" ?
148
- metadata.allowOrigins : [metadata.allowOrigins];
149
-
150
- const allowMethods = !metadata?.allowMethods ?
151
- ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"] : metadata.allowMethods;
152
-
153
151
  app.use((req: Request, res: Response, next: NextFunction) => {
154
- if (!req.headers.origin) {
152
+ if (!allowOrigins.includes(req.headers.origin || "*")) {
155
153
  return res.status(403).json({
156
154
  ["httpCode"]: 403,
157
- ["data"]: "CORS Origin - Not found."
155
+ ["data"]: "Invalid origin."
158
156
  });
159
157
  }
160
158
 
161
- if (!allowOrigins.includes("*")) {
162
- if (!allowOrigins.includes(req.headers.origin)) {
163
- return res.status(403).json({
164
- ["httpCode"]: 403,
165
- ["data"]: "Invalid origin."
166
- });
167
- }
168
- }
169
-
170
- res.header("Access-Control-Allow-Origin", req.headers.origin);
159
+ res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
171
160
  res.header("Access-Control-Allow-Headers", "*");
172
161
  res.header("Access-Control-Allow-Credentials", "true");
173
162
  res.header("Access-Control-Allow-Methods", allowMethods.join(", "));