fix(core): fixed problem with wildcard method type in routing
MODIFY
packages/core/src/effects/effects.combiner.ts
packages/core/src/effects/effects.combiner.ts
-import { from } from 'rxjs';
+import { Observable, from } from 'rxjs';
import { concatMap, last } from 'rxjs/operators';
+import { HttpRequest, HttpResponse } from '../http.interface';
import { Middleware } from './effects.interface';
+export { HttpRequest, HttpResponse, Observable };
export const combineMiddlewareEffects = (effects: Middleware[]): Middleware => {
const middlewaresObservable = from(middlewaresGuard(effects));

MODIFY
packages/core/src/http.listener.ts
packages/core/src/http.listener.ts
import { IncomingMessage, OutgoingMessage } from 'http';
-import { of, Subject } from 'rxjs';
+import { Observable, of, Subject } from 'rxjs';
import { catchError, defaultIfEmpty, mergeMap, switchMap, tap } from 'rxjs/operators';
import { combineMiddlewareEffects } from './effects/effects.combiner';
import { EffectResponse, Middleware, ErrorMiddleware } from './effects/effects.interface';
@@ -9,6 +9,7 @@ import { handleResponse } from './response/response.handler';
import { RouteEffect, RouteEffectGroup } from './router/router.interface';
import { resolveRouting } from './router/router';
import { factorizeRouting } from './router/router.factory';
+export { Observable };
type HttpListenerConfig = {
middlewares?: Middleware[];

MODIFY
packages/core/src/router/router.spec.ts
packages/core/src/router/router.spec.ts
@@ -49,6 +49,29 @@ describe('Router', () => {
params: { param: 'nested' }
});
});
+
+ test('matches wildcard route if doesn\'t found proper route', () => {
+ // given
+ const e1$: Effect = req$ => req$.pipe(mapTo({ body: 'e1' }));
+ const e2$: Effect = req$ => req$.pipe(mapTo({ body: 'e2' }));
+
+ const routing: Routing = [
+ { regExp: /^\/group\/nested\/?$/, methods: { GET: { effect: e1$ } } },
+ { regExp: /^\/group.*?$/, methods: { '*': { effect: e2$ } } }
+ ];
+
+ // when
+ const route1 = findRoute(routing, '/group/test', 'GET');
+ const route2 = findRoute(routing, '/test', 'GET');
+
+ // then
+ expect(route1).toEqual({
+ effect: e2$,
+ middleware: undefined,
+ params: {},
+ });
+ expect(route2).toBeUndefined();
+ });
});
describe('#resolveRouting', () => {

MODIFY
packages/core/src/router/router.ts
packages/core/src/router/router.ts
import { EMPTY, Observable, of } from 'rxjs';
import { HttpMethod, HttpRequest, HttpResponse } from '../http.interface';
import { EffectResponse } from '../effects/effects.interface';
-import { RouteMatched, Routing } from './router.interface';
+import { RouteMatched, Routing, RoutingItem } from './router.interface';
import { queryParamsFactory } from '../router/queryParams.factory';
+export { RoutingItem };
export const findRoute = (
routing: Routing,
@@ -17,10 +18,10 @@ export const findRoute = (
continue;
}
- const routingMethod = methods[method];
+ const routingMethod = methods[method] || methods['*'];
if (!routingMethod) {
- return undefined;
+ continue;
}
const { parameters, effect, middleware } = routingMethod;

fix(core): fixed problem with wildcard method type in routing