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