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

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"
@@ -7,13 +7,16 @@ export const ExpressLive = Layer.sync(Express, () => express())
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(
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