HTTP server work

This commit is contained in:
Julien Valverdé
2024-07-01 11:50:21 +02:00
parent d93c86d60f
commit ba19b1c4a7
5 changed files with 9 additions and 5 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -8,6 +8,7 @@
"@effect/schema": "^0.68.12", "@effect/schema": "^0.68.12",
"@thilawyn/thilalib": "^0.1.4", "@thilawyn/thilalib": "^0.1.4",
"@todo-tests/common": "workspace:*", "@todo-tests/common": "workspace:*",
"@trpc/server": "^10.45.2",
"effect": "^3.4.5", "effect": "^3.4.5",
"express": "^4.19.2" "express": "^4.19.2"
}, },

View File

View File

@@ -1,4 +1,4 @@
import { Context, Effect, Layer } from "effect" import { Config, Context, Effect, Layer } from "effect"
import express from "express" import express from "express"
@@ -7,13 +7,16 @@ export const ExpressLive = Layer.sync(Express, () => express())
export const ServerLive = Layer.scopedDiscard(Effect.gen(function*() { export const ServerLive = Layer.scopedDiscard(Effect.gen(function*() {
const port = 8080 const app = yield* Express
const app = yield* Express const port = yield* Config.number("PORT").pipe(Config.withDefault(8080))
yield* Effect.acquireRelease( yield* Effect.acquireRelease(
Effect.sync(() => Effect.sync(() =>
app.listen(port, () => console.log(`Example app listening on port ${ port }`)) app.listen(port, () => console.log(`HTTP server listening on ${ port }.`))
),
server => Effect.sync(() =>
server.close()
), ),
server => Effect.sync(() => server.close()),
) )
})) }))

View File