HTTP server fix

This commit is contained in:
Julien Valverdé
2024-07-17 23:29:15 +02:00
parent af7d944116
commit ddb531a521

View File

@@ -1,4 +1,4 @@
import { Context, Effect, Layer, Runtime } from "effect"
import { Context, Effect, Layer } from "effect"
import { Server } from "node:http"
import { ServerConfig } from "../ServerConfig"
import { ExpressApp } from "./ExpressApp"
@@ -9,14 +9,16 @@ export class ExpressHTTPServer extends Context.Tag("ExpressHTTPServer")<ExpressH
export module ExpressHTTPServer {
export const Live = Layer.effect(ExpressHTTPServer, Effect.acquireRelease(
Effect.gen(function*() {
const runSync = yield* Effect.runtime().pipe(
Effect.map(Runtime.runSync)
)
const app = yield* ExpressApp
const port = yield* ServerConfig.httpPort
return app.listen(port, () => runSync(Effect.logInfo(`HTTP server listening on ${ port }`)))
return yield* Effect.async<Server>(resume => {
const server = app.listen(port, () => resume(
Effect.succeed(server).pipe(
Effect.tap(Effect.logInfo(`HTTP server listening on ${ port }`))
)
))
})
}),
server => Effect.gen(function*() {