@naturalcycles/backend-lib 9.25.0 → 9.26.0
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.
|
@@ -6,5 +6,8 @@ import type { BackendRequest } from './server.model.js';
|
|
|
6
6
|
*
|
|
7
7
|
* Gets the correct full path when used from sub-router-resources.
|
|
8
8
|
* Strips away the queryString.
|
|
9
|
+
*
|
|
10
|
+
* If stripPrefix (e.g `/api/v2`) is provided, and the path starts with it (like path.startsWith(stripPrefix)),
|
|
11
|
+
* it will be stripped from the beginning of the path.
|
|
9
12
|
*/
|
|
10
|
-
export declare function getRequestEndpoint(req: BackendRequest): string;
|
|
13
|
+
export declare function getRequestEndpoint(req: BackendRequest, stripPrefix?: string): string;
|
|
@@ -5,11 +5,17 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Gets the correct full path when used from sub-router-resources.
|
|
7
7
|
* Strips away the queryString.
|
|
8
|
+
*
|
|
9
|
+
* If stripPrefix (e.g `/api/v2`) is provided, and the path starts with it (like path.startsWith(stripPrefix)),
|
|
10
|
+
* it will be stripped from the beginning of the path.
|
|
8
11
|
*/
|
|
9
|
-
export function getRequestEndpoint(req) {
|
|
12
|
+
export function getRequestEndpoint(req, stripPrefix) {
|
|
10
13
|
let path = (req.baseUrl + (req.route?.path || req.path)).toLowerCase();
|
|
11
14
|
if (path.length > 1 && path.endsWith('/')) {
|
|
12
15
|
path = path.slice(0, path.length - 1);
|
|
13
16
|
}
|
|
17
|
+
if (stripPrefix && path.startsWith(stripPrefix)) {
|
|
18
|
+
path = path.slice(stripPrefix.length);
|
|
19
|
+
}
|
|
14
20
|
return [req.method, path].join(' ');
|
|
15
21
|
}
|
package/package.json
CHANGED
|
@@ -7,12 +7,19 @@ import type { BackendRequest } from './server.model.js'
|
|
|
7
7
|
*
|
|
8
8
|
* Gets the correct full path when used from sub-router-resources.
|
|
9
9
|
* Strips away the queryString.
|
|
10
|
+
*
|
|
11
|
+
* If stripPrefix (e.g `/api/v2`) is provided, and the path starts with it (like path.startsWith(stripPrefix)),
|
|
12
|
+
* it will be stripped from the beginning of the path.
|
|
10
13
|
*/
|
|
11
|
-
export function getRequestEndpoint(req: BackendRequest): string {
|
|
14
|
+
export function getRequestEndpoint(req: BackendRequest, stripPrefix?: string): string {
|
|
12
15
|
let path = (req.baseUrl + (req.route?.path || req.path)).toLowerCase()
|
|
13
16
|
if (path.length > 1 && path.endsWith('/')) {
|
|
14
17
|
path = path.slice(0, path.length - 1)
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
if (stripPrefix && path.startsWith(stripPrefix)) {
|
|
21
|
+
path = path.slice(stripPrefix.length)
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
return [req.method, path].join(' ')
|
|
18
25
|
}
|