ultimate-express 1.1.8 → 1.1.9
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/package.json +1 -1
- package/src/response.js +3 -2
- package/src/router.js +6 -2
- package/src/utils.js +1 -1
package/package.json
CHANGED
package/src/response.js
CHANGED
|
@@ -238,9 +238,10 @@ module.exports = class Response extends Writable {
|
|
|
238
238
|
if(this.headersSent) {
|
|
239
239
|
throw new Error('Can\'t write body: Response was already sent');
|
|
240
240
|
}
|
|
241
|
+
const isBuffer = Buffer.isBuffer(body);
|
|
241
242
|
if(body === null || body === undefined) {
|
|
242
243
|
body = '';
|
|
243
|
-
} else if(typeof body === 'object' && !
|
|
244
|
+
} else if(typeof body === 'object' && !isBuffer) {
|
|
244
245
|
return this.json(body);
|
|
245
246
|
} else if(typeof body === 'number') {
|
|
246
247
|
if(arguments[1]) {
|
|
@@ -250,7 +251,7 @@ module.exports = class Response extends Writable {
|
|
|
250
251
|
deprecated('res.send(status)', 'res.sendStatus(status)');
|
|
251
252
|
return this.sendStatus(body);
|
|
252
253
|
}
|
|
253
|
-
} else {
|
|
254
|
+
} else if(!isBuffer) {
|
|
254
255
|
body = String(body);
|
|
255
256
|
}
|
|
256
257
|
if(typeof body === 'string') {
|
package/src/router.js
CHANGED
|
@@ -303,13 +303,17 @@ module.exports = class Router extends EventEmitter {
|
|
|
303
303
|
|
|
304
304
|
#extractParams(pattern, path) {
|
|
305
305
|
let match = pattern.exec(path);
|
|
306
|
-
|
|
306
|
+
const obj = match?.groups ?? {};
|
|
307
|
+
for(let i = 1; i < match.length; i++) {
|
|
308
|
+
obj[i - 1] = match[i];
|
|
309
|
+
}
|
|
310
|
+
return obj;
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
#preprocessRequest(req, res, route) {
|
|
310
314
|
return new Promise(async resolve => {
|
|
311
315
|
req.route = route;
|
|
312
|
-
if(typeof route.path === 'string' && route.path.includes(':') && route.pattern instanceof RegExp) {
|
|
316
|
+
if(typeof route.path === 'string' && (route.path.includes(':') || route.path.includes('*')) && route.pattern instanceof RegExp) {
|
|
313
317
|
let path = req.path;
|
|
314
318
|
if(req._stack.length > 0) {
|
|
315
319
|
path = path.replace(this.getFullMountpath(req), '');
|
package/src/utils.js
CHANGED
|
@@ -36,7 +36,7 @@ function patternToRegex(pattern, isPrefix = false) {
|
|
|
36
36
|
let regexPattern = pattern
|
|
37
37
|
.replace(/\./g, '\\.')
|
|
38
38
|
.replace(/\-/g, '\\-')
|
|
39
|
-
.replace(/\*/g, '.*') // Convert * to .*
|
|
39
|
+
.replace(/\*/g, '(.*)') // Convert * to .*
|
|
40
40
|
.replace(/:(\w+)(\(.+?\))?/g, (match, param, regex) => {
|
|
41
41
|
return `(?<${param}>${regex ? regex + '($|\\/)' : '[^/]+'})`;
|
|
42
42
|
}); // Convert :param to capture group
|