WebSocket work
This commit is contained in:
9
packages/server/src/http/ExpressApp.ts
Normal file
9
packages/server/src/http/ExpressApp.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Context, Layer } from "effect"
|
||||
import express, { type Express } from "express"
|
||||
|
||||
|
||||
export class ExpressApp extends Context.Tag("ExpressApp")<ExpressApp, Express>() {}
|
||||
|
||||
export module ExpressApp {
|
||||
export const Live = Layer.sync(ExpressApp, () => express())
|
||||
}
|
||||
30
packages/server/src/http/ExpressHTTPServer.ts
Normal file
30
packages/server/src/http/ExpressHTTPServer.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Context, Effect, Layer, Runtime } from "effect"
|
||||
import { Server } from "node:http"
|
||||
import { httpPort } from "../config"
|
||||
import { ExpressApp } from "./ExpressApp"
|
||||
|
||||
|
||||
export class ExpressHTTPServer extends Context.Tag("ExpressHTTPServer")<ExpressHTTPServer, Server>() {}
|
||||
|
||||
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* httpPort
|
||||
|
||||
return app.listen(port, () => runSync(Effect.logInfo(`HTTP server listening on ${ port }`)))
|
||||
}),
|
||||
|
||||
server => Effect.gen(function*() {
|
||||
yield* Effect.logInfo(`HTTP server is closing. Waiting for existing connections to end...`)
|
||||
|
||||
yield* Effect.async(resume => {
|
||||
server.close(() => resume(Effect.logInfo(`HTTP server closed`)))
|
||||
})
|
||||
}),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user