Cleanup
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
import { Context, Effect, Layer } from "effect"
|
|
||||||
import ws from "ws"
|
|
||||||
import { ExpressHTTPServer } from "../http/ExpressHTTPServer"
|
|
||||||
|
|
||||||
|
|
||||||
export class WebSocketServer extends Context.Tag("WebSocketServer")<WebSocketServer, ws.Server>() {}
|
|
||||||
|
|
||||||
export module WebSocketServer {
|
|
||||||
export const Live = Layer.effect(WebSocketServer, Effect.acquireRelease(
|
|
||||||
Effect.gen(function*() {
|
|
||||||
yield* Effect.logInfo("WebSocket server started")
|
|
||||||
return new ws.WebSocketServer({ server: yield* ExpressHTTPServer })
|
|
||||||
}),
|
|
||||||
|
|
||||||
wss => Effect.gen(function*() {
|
|
||||||
yield* Effect.logInfo("WebSocket server is stopping. Waiting for existing connections to end...")
|
|
||||||
yield* Effect.async(resume => {
|
|
||||||
wss.close(() => resume(Effect.logInfo("WebSocket server closed")))
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import { ServerConfig } from "./ServerConfig"
|
|||||||
import { Services } from "./Services"
|
import { Services } from "./Services"
|
||||||
import { ExpressApp } from "./http/ExpressApp"
|
import { ExpressApp } from "./http/ExpressApp"
|
||||||
import { ExpressHTTPServer } from "./http/ExpressHTTPServer"
|
import { ExpressHTTPServer } from "./http/ExpressHTTPServer"
|
||||||
import { WebSocketServer } from "./http/WebSocketServer"
|
|
||||||
import { RPCPlaygroundRoute } from "./rpc/RPCPlaygroundRoute"
|
import { RPCPlaygroundRoute } from "./rpc/RPCPlaygroundRoute"
|
||||||
import { RPCRoute } from "./rpc/RPCRoute"
|
import { RPCRoute } from "./rpc/RPCRoute"
|
||||||
import { RPCRouter } from "./rpc/RPCRouter"
|
import { RPCRouter } from "./rpc/RPCRouter"
|
||||||
@@ -40,7 +39,6 @@ const ServerLive = Layer.empty.pipe(
|
|||||||
Layer.provideMerge(TRPCBuilder.Live),
|
Layer.provideMerge(TRPCBuilder.Live),
|
||||||
Layer.provideMerge(TRPCContextCreator.Live),
|
Layer.provideMerge(TRPCContextCreator.Live),
|
||||||
|
|
||||||
Layer.provideMerge(WebSocketServer.Live),
|
|
||||||
Layer.provideMerge(ExpressHTTPServer.Live),
|
Layer.provideMerge(ExpressHTTPServer.Live),
|
||||||
Layer.provideMerge(ExpressApp.Live),
|
Layer.provideMerge(ExpressApp.Live),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import { applyWSSHandler } from "@trpc/server/adapters/ws"
|
|
||||||
import { Effect, Layer } from "effect"
|
|
||||||
import { WebSocketServer } from "../http/WebSocketServer"
|
|
||||||
import { TRPCContextCreator } from "../trpc/TRPCContextCreator"
|
|
||||||
import { RPCRouter } from "./RPCRouter"
|
|
||||||
|
|
||||||
|
|
||||||
export module RPCWebSocketHandler {
|
|
||||||
export const Live = Layer.effectDiscard(Effect.acquireRelease(
|
|
||||||
Effect.gen(function*() {
|
|
||||||
return applyWSSHandler({
|
|
||||||
wss: yield* WebSocketServer,
|
|
||||||
router: yield* RPCRouter,
|
|
||||||
createContext: (yield* TRPCContextCreator).createWebSocketContext,
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
|
|
||||||
handler => Effect.sync(() =>
|
|
||||||
handler.broadcastReconnectNotification()
|
|
||||||
),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { createLazyFileRoute } from "@tanstack/react-router"
|
import { createLazyFileRoute } from "@tanstack/react-router"
|
||||||
import { Option, flow, identity } from "effect"
|
import { Option, flow, identity } from "effect"
|
||||||
import { IObservableArray, observable } from "mobx"
|
import { type IObservableArray, observable } from "mobx"
|
||||||
import { observer } from "mobx-react-lite"
|
import { observer } from "mobx-react-lite"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { JsonifiableTodo, Todo } from "../data"
|
import { JsonifiableTodo, Todo } from "../data"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
||||||
import { createWSClient, httpBatchLink, splitLink, wsLink } from "@trpc/client"
|
import { createWSClient, httpBatchLink, splitLink, wsLink } from "@trpc/client"
|
||||||
import { ReactNode, useState } from "react"
|
import { type ReactNode, useState } from "react"
|
||||||
import { trpc } from "./trpc"
|
import { trpc } from "./trpc"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user