This commit is contained in:
19
src/Layers/express/ExpressApp.ts
Normal file
19
src/Layers/express/ExpressApp.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Config, Context, Effect, Layer } from "effect"
|
||||
import type { Express } from "express"
|
||||
|
||||
|
||||
export class ExpressApp extends Context.Tag("ExpressApp")<ExpressApp, Express>() {}
|
||||
|
||||
|
||||
const importExpress = Effect.tryPromise({
|
||||
try: () => import("express"),
|
||||
catch: cause => new Error("Could not import 'express'. Make sure it is installed.", { cause }),
|
||||
})
|
||||
|
||||
export const ExpressAppLive = (config: {
|
||||
readonly trustProxy?: Config.Config<boolean>
|
||||
}) => Layer.effect(ExpressApp, Effect.gen(function*() {
|
||||
const app = (yield* importExpress).default()
|
||||
app.set("trust proxy", yield* config.trustProxy || Config.succeed(false))
|
||||
return app
|
||||
}))
|
||||
Reference in New Issue
Block a user