@@ -10,9 +10,11 @@ const importExpress = Effect.tryPromise({
|
|||||||
catch: cause => new Error("Could not import 'express'. Make sure it is installed.", { cause }),
|
catch: cause => new Error("Could not import 'express'. Make sure it is installed.", { cause }),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const ExpressAppLive = (config: {
|
export const ExpressAppLive = (
|
||||||
readonly trustProxy?: Config.Config<boolean>
|
config: {
|
||||||
}) => Layer.effect(ExpressApp, Effect.gen(function*() {
|
readonly trustProxy?: Config.Config<boolean>
|
||||||
|
} = {}
|
||||||
|
) => Layer.effect(ExpressApp, Effect.gen(function*() {
|
||||||
const app = (yield* importExpress).default()
|
const app = (yield* importExpress).default()
|
||||||
app.set("trust proxy", yield* config.trustProxy || Config.succeed(false))
|
app.set("trust proxy", yield* config.trustProxy || Config.succeed(false))
|
||||||
return app
|
return app
|
||||||
|
|||||||
@@ -18,17 +18,19 @@ const serverListeningMessage = Match.type<AddressInfo | string | null>().pipe(
|
|||||||
Match.orElse(v => `HTTP server listening on ${ v.address }:${ v.port }`),
|
Match.orElse(v => `HTTP server listening on ${ v.address }:${ v.port }`),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const ExpressNodeHTTPServerLive = (config: {
|
export const ExpressNodeHTTPServerLive = (
|
||||||
readonly backlog?: Config.Config<number | undefined>
|
config: {
|
||||||
readonly exclusive?: Config.Config<boolean | undefined>
|
readonly backlog?: Config.Config<number | undefined>
|
||||||
readonly host?: Config.Config<string | undefined>
|
readonly exclusive?: Config.Config<boolean | undefined>
|
||||||
readonly ipv6Only?: Config.Config<boolean | undefined>
|
readonly host?: Config.Config<string | undefined>
|
||||||
readonly path?: Config.Config<string | undefined>
|
readonly ipv6Only?: Config.Config<boolean | undefined>
|
||||||
readonly port?: Config.Config<number | undefined>
|
readonly path?: Config.Config<string | undefined>
|
||||||
readonly readableAll?: Config.Config<boolean | undefined>
|
readonly port?: Config.Config<number | undefined>
|
||||||
readonly signal?: AbortSignal
|
readonly readableAll?: Config.Config<boolean | undefined>
|
||||||
readonly writableAll?: Config.Config<boolean | undefined>
|
readonly signal?: AbortSignal
|
||||||
}) => Layer.effect(ExpressNodeHTTPServer, Effect.acquireRelease(
|
readonly writableAll?: Config.Config<boolean | undefined>
|
||||||
|
} = {}
|
||||||
|
) => Layer.effect(ExpressNodeHTTPServer, Effect.acquireRelease(
|
||||||
Effect.gen(function*() {
|
Effect.gen(function*() {
|
||||||
const app = yield* ExpressApp
|
const app = yield* ExpressApp
|
||||||
const http = yield* importNodeHTTP
|
const http = yield* importNodeHTTP
|
||||||
|
|||||||
17
src/Layers/express/tests.ts
Normal file
17
src/Layers/express/tests.ts
Normal file
@@ -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,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user