@bool-ts/core 1.2.3 → 1.2.4
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 +22 -21
- package/package.json +1 -1
- package/src/hooks/factory.ts +29 -26
package/dist/hooks/factory.js
CHANGED
|
@@ -123,27 +123,7 @@ const BoolFactory = (target, options) => {
|
|
|
123
123
|
req.body = Object.freeze({});
|
|
124
124
|
}
|
|
125
125
|
next();
|
|
126
|
-
}
|
|
127
|
-
// Error catcher
|
|
128
|
-
(err, req, res, next) => {
|
|
129
|
-
(0, http_1.errorInfer)(res, err);
|
|
130
|
-
if (!options?.debug) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
console.error("Headers:", JSON.stringify(req.headers), "\nBody:", JSON.stringify(req.body), "\nError:", JSON.stringify(err));
|
|
134
|
-
},
|
|
135
|
-
// Response time log
|
|
136
|
-
ResponseTime.default((req, res, time) => {
|
|
137
|
-
const requestMethod = req.method.toUpperCase();
|
|
138
|
-
if (!factoryOptions.allowLogsMethods.includes(requestMethod)) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const convertedMethod = `${requestMethod.yellow}`.bgBlue;
|
|
142
|
-
const convertedPID = `${process.pid}`.yellow;
|
|
143
|
-
const convertedReqIp = `${req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || req.ip || "<Unknown>"}`.yellow;
|
|
144
|
-
const convertedTime = `${Math.round((time + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
|
|
145
|
-
console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
|
|
146
|
-
}));
|
|
126
|
+
});
|
|
147
127
|
app.use((req, res, next) => {
|
|
148
128
|
if (!allowOrigins.includes("*")) {
|
|
149
129
|
if (!allowOrigins.includes(req.headers.origin || "*")) {
|
|
@@ -169,6 +149,27 @@ const BoolFactory = (target, options) => {
|
|
|
169
149
|
app.use(routers) : app.use(!metadata.prefix.startsWith("/") ?
|
|
170
150
|
`/${metadata.prefix}` : metadata.prefix, routers);
|
|
171
151
|
}
|
|
152
|
+
app.use(
|
|
153
|
+
// Error catcher
|
|
154
|
+
(err, req, res, next) => {
|
|
155
|
+
(0, http_1.errorInfer)(res, err);
|
|
156
|
+
if (!options?.debug) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.error("Headers:", JSON.stringify(req.headers), "\nBody:", JSON.stringify(req.body), "\nError:", JSON.stringify(err));
|
|
160
|
+
},
|
|
161
|
+
// Response time log
|
|
162
|
+
ResponseTime.default((req, res, time) => {
|
|
163
|
+
const requestMethod = req.method.toUpperCase();
|
|
164
|
+
if (!factoryOptions.allowLogsMethods.includes(requestMethod)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const convertedMethod = `${requestMethod.yellow}`.bgBlue;
|
|
168
|
+
const convertedPID = `${process.pid}`.yellow;
|
|
169
|
+
const convertedReqIp = `${req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || req.ip || "<Unknown>"}`.yellow;
|
|
170
|
+
const convertedTime = `${Math.round((time + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
|
|
171
|
+
console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
|
|
172
|
+
}));
|
|
172
173
|
return app;
|
|
173
174
|
};
|
|
174
175
|
exports.BoolFactory = BoolFactory;
|
package/package.json
CHANGED
package/src/hooks/factory.ts
CHANGED
|
@@ -136,32 +136,7 @@ export const BoolFactory = (
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
next();
|
|
139
|
-
}
|
|
140
|
-
// Error catcher
|
|
141
|
-
(err: Errback, req: Request, res: Response, next: NextFunction) => {
|
|
142
|
-
errorInfer(res, err);
|
|
143
|
-
|
|
144
|
-
if (!options?.debug) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
console.error("Headers:", JSON.stringify(req.headers), "\nBody:", JSON.stringify(req.body), "\nError:", JSON.stringify(err));
|
|
149
|
-
},
|
|
150
|
-
// Response time log
|
|
151
|
-
ResponseTime.default((req: Request, res: Response, time: number) => {
|
|
152
|
-
const requestMethod = req.method.toUpperCase();
|
|
153
|
-
|
|
154
|
-
if (!factoryOptions.allowLogsMethods.includes(requestMethod)) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const convertedMethod = `${requestMethod.yellow}`.bgBlue;
|
|
159
|
-
const convertedPID = `${process.pid}`.yellow;
|
|
160
|
-
const convertedReqIp = `${req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || req.ip || "<Unknown>"}`.yellow;
|
|
161
|
-
const convertedTime = `${Math.round((time + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
|
|
162
|
-
|
|
163
|
-
console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
|
|
164
|
-
})
|
|
139
|
+
}
|
|
165
140
|
);
|
|
166
141
|
|
|
167
142
|
app.use((req: Request, res: Response, next: NextFunction) => {
|
|
@@ -193,6 +168,34 @@ export const BoolFactory = (
|
|
|
193
168
|
`/${metadata.prefix}` : metadata.prefix, routers);
|
|
194
169
|
}
|
|
195
170
|
|
|
171
|
+
app.use(
|
|
172
|
+
// Error catcher
|
|
173
|
+
(err: Errback, req: Request, res: Response, next: NextFunction) => {
|
|
174
|
+
errorInfer(res, err);
|
|
175
|
+
|
|
176
|
+
if (!options?.debug) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.error("Headers:", JSON.stringify(req.headers), "\nBody:", JSON.stringify(req.body), "\nError:", JSON.stringify(err));
|
|
181
|
+
},
|
|
182
|
+
// Response time log
|
|
183
|
+
ResponseTime.default((req: Request, res: Response, time: number) => {
|
|
184
|
+
const requestMethod = req.method.toUpperCase();
|
|
185
|
+
|
|
186
|
+
if (!factoryOptions.allowLogsMethods.includes(requestMethod)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const convertedMethod = `${requestMethod.yellow}`.bgBlue;
|
|
191
|
+
const convertedPID = `${process.pid}`.yellow;
|
|
192
|
+
const convertedReqIp = `${req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || req.ip || "<Unknown>"}`.yellow;
|
|
193
|
+
const convertedTime = `${Math.round((time + Number.EPSILON) * 10 ** 2) / 10 ** 2}ms`.yellow;
|
|
194
|
+
|
|
195
|
+
console.info(`PID: ${convertedPID} - Method: ${convertedMethod} - IP: ${convertedReqIp} - ${req.originalUrl.blue} - Time: ${convertedTime}`);
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
|
|
196
199
|
return app;
|
|
197
200
|
}
|
|
198
201
|
|