refactor(integration): cqrs and websockets server bootstrapping
MODIFY
packages/@integration/src/cqrs/index.ts
packages/@integration/src/cqrs/index.ts
-import { IO } from 'fp-ts/lib/IO';
+import * as T from 'fp-ts/lib/Task';
+import { pipe } from 'fp-ts/lib/pipeable';
import { isTestEnv, getPortEnv } from '@marblejs/core/dist/+internal/utils';
import { httpListener, createServer, bindEagerlyTo } from '@marblejs/core';
import { messagingListener, EventBusClientToken, eventBusClient, EventBusToken, eventBus } from '@marblejs/messaging';
@@ -24,7 +25,7 @@ const listener = httpListener({
],
});
-export const server = createServer({
+export const server = () => createServer({
port: getPortEnv(),
listener,
dependencies: [
@@ -33,7 +34,8 @@ export const server = createServer({
],
});
-const main: IO<void> = async () =>
- !isTestEnv() && await (await server)();
+export const main = !isTestEnv()
+ ? pipe(server, T.map(run => run()))
+ : T.of(undefined);
main();

MODIFY
packages/@integration/src/websockets/http.server.ts
packages/@integration/src/websockets/http.server.ts
@@ -13,7 +13,8 @@ import {
import { mapToServer, WebSocketServerConnection } from '@marblejs/websockets';
import { logger$ } from '@marblejs/middleware-logger';
import { isTestEnv } from '@marblejs/core/dist/+internal/utils';
-import { IO } from 'fp-ts/lib/IO';
+import * as T from 'fp-ts/lib/Task';
+import { pipe } from 'fp-ts/lib/pipeable';
import { tap, map } from 'rxjs/operators';
import { webSocketServer } from './websockets.server';
@@ -40,23 +41,30 @@ const upgrade$: HttpServerEffect = (event$, ctx) =>
}),
);
-export const server = createServer({
- port: 1337,
- listener: httpListener({
- middlewares: [logger$()],
- effects: [root$],
- }),
- dependencies: [
+const event$ = combineEffects(
+ upgrade$,
+);
+
+const dependencies = [
bindEagerlyTo(WebSocketServerToken)(async () =>
(await webSocketServer)()
),
- ],
- event$: combineEffects(
- upgrade$,
- ),
+];
+
+const listener = httpListener({
+ middlewares: [logger$()],
+ effects: [root$],
+});
+
+export const server = () => createServer({
+ port: 1337,
+ listener,
+ dependencies,
+ event$,
});
-const main: IO<void> = async () =>
- !isTestEnv() && await (await server)();
+export const main = !isTestEnv()
+ ? pipe(server, T.map(run => run()))
+ : T.of(undefined);
main();

refactor(integration): cqrs and websockets server bootstrapping