diff --git a/src/Layers/express/ExpressApp.ts b/src/Layers/express/ExpressApp.ts index bcf72a6..4548211 100644 --- a/src/Layers/express/ExpressApp.ts +++ b/src/Layers/express/ExpressApp.ts @@ -10,9 +10,11 @@ const importExpress = Effect.tryPromise({ catch: cause => new Error("Could not import 'express'. Make sure it is installed.", { cause }), }) -export const ExpressAppLive = (config: { - readonly trustProxy?: Config.Config -}) => Layer.effect(ExpressApp, Effect.gen(function*() { +export const ExpressAppLive = ( + config: { + readonly trustProxy?: Config.Config + } = {} +) => Layer.effect(ExpressApp, Effect.gen(function*() { const app = (yield* importExpress).default() app.set("trust proxy", yield* config.trustProxy || Config.succeed(false)) return app diff --git a/src/Layers/express/ExpressNodeHTTPServer.ts b/src/Layers/express/ExpressNodeHTTPServer.ts index c634979..3ce7577 100644 --- a/src/Layers/express/ExpressNodeHTTPServer.ts +++ b/src/Layers/express/ExpressNodeHTTPServer.ts @@ -18,17 +18,19 @@ const serverListeningMessage = Match.type().pipe( Match.orElse(v => `HTTP server listening on ${ v.address }:${ v.port }`), ) -export const ExpressNodeHTTPServerLive = (config: { - readonly backlog?: Config.Config - readonly exclusive?: Config.Config - readonly host?: Config.Config - readonly ipv6Only?: Config.Config - readonly path?: Config.Config - readonly port?: Config.Config - readonly readableAll?: Config.Config - readonly signal?: AbortSignal - readonly writableAll?: Config.Config -}) => Layer.effect(ExpressNodeHTTPServer, Effect.acquireRelease( +export const ExpressNodeHTTPServerLive = ( + config: { + readonly backlog?: Config.Config + readonly exclusive?: Config.Config + readonly host?: Config.Config + readonly ipv6Only?: Config.Config + readonly path?: Config.Config + readonly port?: Config.Config + readonly readableAll?: Config.Config + readonly signal?: AbortSignal + readonly writableAll?: Config.Config + } = {} +) => Layer.effect(ExpressNodeHTTPServer, Effect.acquireRelease( Effect.gen(function*() { const app = yield* ExpressApp const http = yield* importNodeHTTP diff --git a/src/Layers/express/tests.ts b/src/Layers/express/tests.ts new file mode 100644 index 0000000..01900f7 --- /dev/null +++ b/src/Layers/express/tests.ts @@ -0,0 +1,17 @@ +import { Config, Effect, Layer } from "effect" +import { ExpressAppLive } from "./ExpressApp" +import { ExpressNodeHTTPServerLive } from "./ExpressNodeHTTPServer" + + +const AppLive = ExpressAppLive() +const HTTPServerLive = ExpressNodeHTTPServerLive() + +const ServerLive = Layer.empty.pipe( + Layer.provideMerge(HTTPServerLive), + Layer.provideMerge(AppLive), +) + +Layer.launch(ServerLive).pipe( + Effect.scoped, + Effect.runPromise, +)