style(core): moved router defaults to separate file
MODIFY
packages/core/src/listener/http.listener.ts
packages/core/src/listener/http.listener.ts
import { IncomingMessage, OutgoingMessage } from 'http';
import { pipe } from 'fp-ts/lib/pipeable';
import * as R from 'fp-ts/lib/Reader';
-import { throwError } from 'rxjs';
-import { mergeMap } from 'rxjs/operators';
import { combineMiddlewares } from '../effects/effects.combiner';
import {
HttpMiddlewareEffect,
@@ -13,13 +11,11 @@ import { HttpRequest, HttpResponse, HttpStatus } from '../http.interface';
import { handleResponse } from '../response/response.handler';
import { RouteEffect, RouteEffectGroup, RoutingItem } from '../router/router.interface';
import { resolveRouting } from '../router/router.resolver.v2';
-import { factorizeRouting } from '../router/router.factory';
+import { factorizeRoutingWithDefaults } from '../router/router.factory';
import { Context, lookup } from '../context/context.factory';
import { createEffectContext } from '../effects/effectsContext.factory';
import { useContext } from '../context/context.hook';
import { ServerClientToken } from '../server/server.tokens';
-import { r } from '../router/router.ixbuilder';
-import { HttpError } from '../error/error.model';
export interface HttpListenerConfig {
middlewares?: HttpMiddlewareEffect[];
@@ -41,21 +37,11 @@ export const httpListener = ({
}: HttpListenerConfig): R.Reader<Context, HttpListener> => pipe(
R.ask<Context>(),
R.map(ctx => {
-
- const notFound$ = r.pipe(
- r.matchPath('*'),
- r.matchType('*'),
- r.useEffect(req$ => req$.pipe(
- mergeMap(() => throwError(
- new HttpError('Route not found', HttpStatus.NOT_FOUND)
- )),
- )));
-
const ask = lookup(ctx);
const client = useContext(ServerClientToken)(ask);
const effectContext = createEffectContext({ ask, client });
const middleware$ = combineMiddlewares(...middlewares);
- const routing = factorizeRouting([...effects, notFound$]);
+ const routing = factorizeRoutingWithDefaults(effects);
const { resolve, outputSubject } = resolveRouting(routing, effectContext)(middleware$, output$, error$);
const httpServer = (req: IncomingMessage, res: OutgoingMessage) => {

ADD
packages/core/src/router/router.effects.ts
+import { throwError } from 'rxjs';
+import { mergeMap } from 'rxjs/operators';
+import { r } from './router.ixbuilder';
+import { HttpError } from '../error/error.model';
+import { HttpStatus } from '../http.interface';
+
+export const notFound$ = r.pipe(
+ r.matchPath('*'),
+ r.matchType('*'),
+ r.useEffect(req$ => req$.pipe(
+ mergeMap(() => throwError(
+ new HttpError('Route not found', HttpStatus.NOT_FOUND)
+ )),
+ )));

MODIFY
packages/core/src/router/router.factory.ts
packages/core/src/router/router.factory.ts
@@ -10,6 +10,7 @@ import {
} from './router.interface';
import { factorizeRegExpWithParams } from './router.params.factory';
import { isNonNullable } from '../+internal/utils';
+import { notFound$ } from './router.effects';
export const factorizeRouting = (
routes: (RouteEffect | RouteEffectGroup)[],
@@ -57,3 +58,5 @@ export const factorizeRouting = (
return routing;
};
+export const factorizeRoutingWithDefaults = (routes: (RouteEffect | RouteEffectGroup)[]): Routing =>
+ factorizeRouting([...routes, notFound$]);

style(core): moved router defaults to separate file