Config refactoring

This commit is contained in:
Julien Valverdé
2024-07-15 05:01:24 +02:00
parent 000c5bda35
commit f4eeb66459
6 changed files with 50 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
import { BunRuntime } from "@effect/platform-bun"
import { Todo } from "@todo-tests/common/data"
import { Duration, Effect, Layer, Option } from "effect"
import { Duration, Effect, Layer, Match, Option } from "effect"
import { ServerConfig } from "./ServerConfig"
import { Services } from "./Services"
import { ExpressApp } from "./http/ExpressApp"
import { ExpressHTTPServer } from "./http/ExpressHTTPServer"
@@ -30,8 +31,24 @@ const ServerDev = Layer.empty.pipe(
Layer.provideMerge(ExpressApp.Live),
)
const ServerLive = Layer.empty.pipe(
Layer.provideMerge(RPCRoute.Live),
Layer.provideMerge(RPCPlaygroundRoute.Live),
Layer.provideMerge(RPCWebSocketHandler.Live),
Layer.provideMerge(RPCRouter.Live),
Layer.provideMerge(RPCProcedureBuilder.Live),
Layer.provideMerge(TRPCBuilder.Live),
Layer.provideMerge(TRPCContextCreator.Live),
Layer.provideMerge(WebSocketServer.Live),
Layer.provideMerge(ExpressHTTPServer.Live),
Layer.provideMerge(ExpressApp.Live),
)
const main = Effect.gen(function*() {
const mode = yield* ServerConfig.mode
const todos = yield* TodoRepository
yield* todos.add(new Todo({
@@ -79,7 +96,11 @@ const main = Effect.gen(function*() {
)
yield* Layer.launch(ServerDev)
return yield* Layer.launch(Match.value(mode).pipe(
Match.when("development", () => ServerDev),
Match.when("production", () => ServerLive),
Match.exhaustive,
))
})
BunRuntime.runMain(main.pipe(