ultimate-express 1.1.7 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/response.js CHANGED
@@ -139,6 +139,9 @@ module.exports = class Response extends Writable {
139
139
  if(!ok) {
140
140
  // wait until uWS is ready to accept more data
141
141
  this._res.onWritable((offset) => {
142
+ if(this.aborted) {
143
+ return true;
144
+ }
142
145
  const [ok, done] = this._res.tryEnd(chunk.slice(offset - lastOffset), this.totalSize);
143
146
  if(done) {
144
147
  this.destroy();
@@ -147,6 +150,8 @@ module.exports = class Response extends Writable {
147
150
  } else if(ok) {
148
151
  callback();
149
152
  }
153
+
154
+ return ok;
150
155
  });
151
156
  } else {
152
157
  callback();
@@ -233,9 +238,10 @@ module.exports = class Response extends Writable {
233
238
  if(this.headersSent) {
234
239
  throw new Error('Can\'t write body: Response was already sent');
235
240
  }
241
+ const isBuffer = Buffer.isBuffer(body);
236
242
  if(body === null || body === undefined) {
237
243
  body = '';
238
- } else if(typeof body === 'object' && !Buffer.isBuffer(body)) {
244
+ } else if(typeof body === 'object' && !isBuffer) {
239
245
  return this.json(body);
240
246
  } else if(typeof body === 'number') {
241
247
  if(arguments[1]) {
@@ -245,7 +251,7 @@ module.exports = class Response extends Writable {
245
251
  deprecated('res.send(status)', 'res.sendStatus(status)');
246
252
  return this.sendStatus(body);
247
253
  }
248
- } else {
254
+ } else if(!isBuffer) {
249
255
  body = String(body);
250
256
  }
251
257
  if(typeof body === 'string') {
@@ -742,7 +748,10 @@ function pipeStreamOverResponse(res, readStream, totalSize, callback) {
742
748
  res._res.ab = ab;
743
749
  res._res.abOffset = lastOffset;
744
750
 
745
- res._res.onWritable((offset) => {
751
+ res._res.onWritable((offset) => {
752
+ if(res.aborted) {
753
+ return true;
754
+ }
746
755
  const [ok, done] = res._res.tryEnd(res._res.ab.slice(offset - res._res.abOffset), totalSize);
747
756
  if (done) {
748
757
  readStream.destroy();
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
- return match?.groups ?? {};
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