RPCPlayground
This commit is contained in:
@@ -6,6 +6,7 @@ import { ServicesLive } from "./Services"
|
||||
import { TodoRepository, createDefaultTodos } from "./TodoRepository"
|
||||
import { ExpressApp } from "./express/ExpressApp"
|
||||
import { ExpressHTTPServer } from "./express/ExpressHTTPServer"
|
||||
import { RPCPlayground } from "./rpc/RPCPlayground"
|
||||
import { RPCServer } from "./rpc/RPCServer"
|
||||
import { RPCProcedureBuilder } from "./rpc/procedures/RPCProcedureBuilder"
|
||||
import { TRPCBuilder } from "./trpc/TRPCBuilder"
|
||||
@@ -14,6 +15,7 @@ import { TRPCContextCreator } from "./trpc/TRPCContextCreator"
|
||||
|
||||
const ServerLive = ExpressHTTPServer.Live.pipe(
|
||||
Layer.provide(RPCServer.Live),
|
||||
Layer.provide(RPCPlayground.Dev),
|
||||
Layer.provide(RPCProcedureBuilder.Live),
|
||||
Layer.provide(TRPCBuilder.Live),
|
||||
Layer.provide(TRPCContextCreator.Live),
|
||||
|
||||
25
packages/server/src/rpc/RPCPlayground.ts
Normal file
25
packages/server/src/rpc/RPCPlayground.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Config, Effect, Layer } from "effect"
|
||||
import { expressHandler } from "trpc-playground/handlers/express"
|
||||
import { ExpressApp } from "../express/ExpressApp"
|
||||
import { appRouter } from "./routers"
|
||||
|
||||
|
||||
export module RPCPlayground {
|
||||
export const Live = Layer.empty
|
||||
|
||||
export const Dev = Layer.effectDiscard(Effect.gen(function*() {
|
||||
const app = yield* ExpressApp
|
||||
const router = yield* appRouter
|
||||
|
||||
const playgroundEndpoint = yield* Config.string("RPC_PANEL_ROOT").pipe(Config.withDefault("/rpc/playground"))
|
||||
const trpcApiEndpoint = yield* Config.string("RPC_ROOT").pipe(Config.withDefault("/rpc"))
|
||||
|
||||
app.use(playgroundEndpoint,
|
||||
yield* Effect.promise(() => expressHandler({
|
||||
trpcApiEndpoint,
|
||||
playgroundEndpoint,
|
||||
router,
|
||||
}))
|
||||
)
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user