express-api-stress-tester 2.0.3 → 2.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/worker.js +23 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-api-stress-tester",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "High-performance distributed API stress testing platform for Express.js APIs — simulate up to 10M concurrent virtual users",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -94,6 +94,24 @@ let maxLatency = -Infinity;
94
94
  const statusCodes = {};
95
95
  const perEndpoint = {};
96
96
 
97
+ function normalizeBaseForRelativeUrlResolution(base, maybeRelativePath) {
98
+ if (!base || !maybeRelativePath) return base;
99
+ if (maybeRelativePath.startsWith('http://') || maybeRelativePath.startsWith('https://')) return base;
100
+ if (maybeRelativePath.startsWith('/')) return base;
101
+
102
+ try {
103
+ const parsedBase = new URL(base);
104
+ if (parsedBase.pathname && !parsedBase.pathname.endsWith('/')) {
105
+ parsedBase.pathname = `${parsedBase.pathname}/`;
106
+ return parsedBase.toString();
107
+ }
108
+ } catch {
109
+ // ignore
110
+ }
111
+
112
+ return base;
113
+ }
114
+
97
115
  /**
98
116
  * Resolve the full URL for a route.
99
117
  */
@@ -102,7 +120,8 @@ function resolveUrl(route) {
102
120
  const path = route.path || route.url || '';
103
121
  try {
104
122
  if (path) {
105
- return new URL(path, base).toString();
123
+ const normalizedBase = normalizeBaseForRelativeUrlResolution(base, path);
124
+ return new URL(path, normalizedBase).toString();
106
125
  }
107
126
  if (base) {
108
127
  return new URL(base).toString();
@@ -326,7 +345,9 @@ async function executeRequest(task) {
326
345
  parsed = new URL(targetUrl);
327
346
  } catch {
328
347
  try {
329
- parsed = new URL(targetUrl, config.baseUrl || config.url);
348
+ const base = config.baseUrl || config.url;
349
+ const normalizedBase = normalizeBaseForRelativeUrlResolution(base, targetUrl);
350
+ parsed = new URL(targetUrl, normalizedBase);
330
351
  } catch (err) {
331
352
  throw new Error(
332
353
  `Failed to resolve URL "${targetUrl}" with base "${config.baseUrl || config.url}": ${err.message}`,