diff --git a/bun.lockb b/bun.lockb index 690ee21..a6e4ede 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/server/src/express/ExpressApp.ts b/packages/server/src/express/ExpressApp.ts index 321ab08..fb327e6 100644 --- a/packages/server/src/express/ExpressApp.ts +++ b/packages/server/src/express/ExpressApp.ts @@ -2,7 +2,7 @@ import { Context, Layer } from "effect" import express, { type Express } from "express" -export class ExpressApp extends Context.Tag("Express")() {} +export class ExpressApp extends Context.Tag("ExpressApp")() {} export module ExpressApp { export const Live = Layer.sync(ExpressApp, () => express()) diff --git a/packages/server/src/express/ExpressHTTPServer.ts b/packages/server/src/express/ExpressHTTPServer.ts index e17efd5..6191476 100644 --- a/packages/server/src/express/ExpressHTTPServer.ts +++ b/packages/server/src/express/ExpressHTTPServer.ts @@ -1,19 +1,31 @@ -import { Effect, Layer } from "effect" +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")() {} + export module ExpressHTTPServer { export const Live = Layer.scopedDiscard(Effect.acquireRelease( - Effect.gen(function*() { - const app = yield* ExpressApp - const port = yield* httpPort + Effect.gen(function*() { + const runSync = yield* Effect.runtime().pipe( + Effect.map(Runtime.runSync) + ) - return app.listen(port, () => console.log(`HTTP server listening on ${ port }.`)) - }), + const app = yield* ExpressApp + const port = yield* httpPort - server => Effect.sync(() => - server.close() - ), - )) + 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`))) + }) + }), + ) + ) } diff --git a/packages/server/src/rpc/RPCWebSocketServer.ts b/packages/server/src/rpc/RPCWebSocketServer.ts index 303b3f4..4fb7d2c 100644 --- a/packages/server/src/rpc/RPCWebSocketServer.ts +++ b/packages/server/src/rpc/RPCWebSocketServer.ts @@ -1,6 +1,6 @@ import { applyWSSHandler } from "@trpc/server/adapters/ws" -import { Effect, Layer } from "effect" -import ws from "ws" +import { Effect, Layer, Runtime } from "effect" +import { WebSocketServer } from "ws" import { websocketPort } from "../config" import { TRPCContextCreator } from "../trpc/TRPCContextCreator" import { RPCRouter } from "./RPCRouter" @@ -9,7 +9,11 @@ import { RPCRouter } from "./RPCRouter" export module RPCWebSocketServer { export const Live = Layer.scopedDiscard(Effect.acquireRelease( Effect.gen(function*() { - const wss = new ws.Server({ port: yield* websocketPort }) + const runSync = yield* Effect.runtime().pipe( + Effect.map(Runtime.runSync) + ) + + const wss = new WebSocketServer({ port: yield* websocketPort }) const handler = applyWSSHandler({ wss, diff --git a/packages/webui/package.json b/packages/webui/package.json index 446d49b..69a4ce8 100644 --- a/packages/webui/package.json +++ b/packages/webui/package.json @@ -20,8 +20,7 @@ "mobx-react-lite": "^4.0.7", "primereact": "^10.7.0", "react": "^18.3.1", - "react-dom": "^18.3.1", - "ws": "^8.18.0" + "react-dom": "^18.3.1" }, "devDependencies": { "@types/react": "^18.3.3",