improvement - matchPath operator - remove query parameters from url
MODIFY
src/effects/effects.combiner.ts
src/effects/effects.combiner.ts
@@ -17,11 +17,6 @@ export const combineEffects: EffectCombiner = effects => res => req => {
return merge(...mappedEffects);
};
-export const combineRoutes: RoutesCombiner = (path, effects) => ({
- path,
- effects
-});
-
export const combineMiddlewareEffects: MiddlewareCombiner = effects => res => req => {
const req$ = of(req);
const mappedEffects = effects.map(effect =>
@@ -29,3 +24,6 @@ export const combineMiddlewareEffects: MiddlewareCombiner = effects => res => re
);
return req$.pipe(...mappedEffects);
};
+
+export const combineRoutes: RoutesCombiner = (path, effects) =>
+ ({ path, effects });

MODIFY
src/http.interface.ts
src/http.interface.ts
@@ -22,8 +22,3 @@ export enum HttpStatus {
INTERNAL_SERVER_ERROR = 500,
SERVICE_UNAVAILABLE = 503,
}
-
-export type Http = {
- req: HttpRequest,
- res: HttpResponse,
-};

MODIFY
src/operators/matchPath.operator.ts
src/operators/matchPath.operator.ts
@@ -3,18 +3,28 @@ import { Observable } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { HttpRequest } from '../http.interface';
-const removeTrailingSlash = (path: string) =>
+const removeTrailingSlash = (path: string): string =>
path.replace(/\/$/, '');
-const pathFactory = (matchers: string[], path: string, suffix?: string) =>
- matchers.reduce((prev, cur) => prev + cur, '') + path + (suffix || '');
+const removeQueryParams = (path: string): string =>
+ path.split('?')[0];
+
+const pathFactory = (matchers: string[], path: string, suffix?: string): string =>
+ removeTrailingSlash(
+ matchers.reduce((prev, cur) => prev + cur, '')
+ + path + (suffix || '')
+ );
+
+const urlFactory = (path: string): string =>
+ removeQueryParams(path);
export const matchPath = (path: string, suffix?: string) => (source$: Observable<HttpRequest>) =>
source$.pipe(
tap(req => req.matchers = req.matchers || []),
filter(req => {
- const mappedPaths = removeTrailingSlash(pathFactory(req.matchers!, path, suffix));
- return pathToRegexp(mappedPaths).test(req.url!);
+ const match = pathFactory(req.matchers!, path, suffix);
+ const url = urlFactory(req.url!);
+ return pathToRegexp(match).test(url);
}),
tap(req => (path !== '/') && req.matchers!.push(path))
);

improvement - matchPath operator - remove query parameters from url