ultimate-express 1.2.24 → 1.2.26

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/README.md CHANGED
@@ -119,7 +119,7 @@ Optimized routes can be up to 10 times faster than normal routes, as they're usi
119
119
 
120
120
  Since you don't create http server manually, you can't properly use http.on("upgrade") to handle WebSockets. To solve this, there's currently 2 options:
121
121
 
122
- - There's currently another library in works: [Ultimate WS](https://github.com/dimdenGD/ultimate-ws) that implements `ws` module. It's same concept as this library, but for WebSockets: fast drop-in replacement for `ws` module with support for uExpress upgrades.
122
+ - There's a sister library that implements `ws` compatible API: [Ultimate WS](https://github.com/dimdenGD/ultimate-ws). It's same concept as this library, but for WebSockets: fast drop-in replacement for `ws` module with support for Ultimate Express upgrades. There's a guide for how to upgrade http requests in the documentation.
123
123
  - You can simply use `app.uwsApp` to access uWebSockets.js `App` instance and call its `ws()` method directly.
124
124
 
125
125
  ## Compatibility
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.24",
3
+ "version": "1.2.26",
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/router.js CHANGED
@@ -417,12 +417,18 @@ module.exports = class Router extends EventEmitter {
417
417
  return resolve(this._routeRequest(req, res, 0, this._routes, false, skipUntil));
418
418
  }
419
419
  let callbackindex = 0;
420
- let continueRoute = await this._preprocessRequest(req, res, route);
420
+ const continueRoute = await this._preprocessRequest(req, res, route);
421
421
  if(route.use) {
422
+ const strictRouting = this.get('strict routing');
422
423
  req._stack.push(route.path);
423
- req._opPath =
424
- req.path.replace(this.getFullMountpath(req), '') +
425
- (req.endsWithSlash && req.path !== '/' && this.get('strict routing') ? '/' : '');
424
+ req._opPath = req.path.replace(this.getFullMountpath(req), '');
425
+ if(strictRouting) {
426
+ if(req.endsWithSlash && req.path !== '/') {
427
+ req._opPath += '/';
428
+ }
429
+ } else if(req.endsWithSlash && req.path !== '/') {
430
+ req._opPath = req._opPath.slice(0, -1);
431
+ }
426
432
  req.url = req._opPath + req.urlQuery;
427
433
  if(req.url === '') req.url = '/';
428
434
  }
@@ -431,9 +437,15 @@ module.exports = class Router extends EventEmitter {
431
437
  if(thingamabob === 'route' || thingamabob === 'skipPop') {
432
438
  if(route.use && thingamabob !== 'skipPop') {
433
439
  req._stack.pop();
434
- req._opPath =
435
- (req._stack.length > 0 ? req.path.replace(this.getFullMountpath(req), '') : req.path) +
436
- (req.endsWithSlash && req.path !== '/' && this.get('strict routing') ? '/' : '');
440
+ const strictRouting = this.get('strict routing');
441
+ req._opPath = req._stack.length > 0 ? req.path.replace(this.getFullMountpath(req), '') : req.path;
442
+ if(strictRouting) {
443
+ if(req.endsWithSlash && req.path !== '/') {
444
+ req._opPath += '/';
445
+ }
446
+ } else if(req.endsWithSlash && req.path !== '/' && req._opPath[req._opPath.length - 1] === '/') {
447
+ req._opPath = req._opPath.slice(0, -1);
448
+ }
437
449
  req.url = req._opPath + req.urlQuery;
438
450
  if(req.url === '') req.url = '/';
439
451
  if(req.app.parent && route.callback.constructor.name === 'Application') {
@@ -457,6 +469,9 @@ module.exports = class Router extends EventEmitter {
457
469
  if(callback.settings.mergeParams) {
458
470
  req._paramStack.push(req.params);
459
471
  }
472
+ if(callback.settings['strict routing'] && req.endsWithSlash && req.path !== '/') {
473
+ req._opPath += '/';
474
+ }
460
475
  const routed = await callback._routeRequest(req, res, 0);
461
476
  if(routed) return resolve(true);
462
477
  next();