Config refactoring
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user