Express work
This commit is contained in:
@@ -2,7 +2,7 @@ import { Context, Layer } from "effect"
|
||||
import express, { type Express } from "express"
|
||||
|
||||
|
||||
export class ExpressApp extends Context.Tag("Express")<ExpressApp, Express>() {}
|
||||
export class ExpressApp extends Context.Tag("ExpressApp")<ExpressApp, Express>() {}
|
||||
|
||||
export module ExpressApp {
|
||||
export const Live = Layer.sync(ExpressApp, () => express())
|
||||
|
||||
@@ -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")<ExpressHTTPServer, Server>() {}
|
||||
|
||||
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`)))
|
||||
})
|
||||
}),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user