0.1.17 #18
21
src/Layers/trpc/TRPCExpressRoute.ts
Normal file
21
src/Layers/trpc/TRPCExpressRoute.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createExpressMiddleware } from "@trpc/server/adapters/express"
|
||||
import { Config, Effect, Layer } from "effect"
|
||||
import { ExpressApp } from "../express"
|
||||
import { TRPCUnknownContextCreator } from "./TRPCContextCreator"
|
||||
import { TRPCAnyRouter } from "./TRPCRouter"
|
||||
|
||||
|
||||
export const TRPCExpressRouteLive = (
|
||||
config: {
|
||||
readonly path: Config.Config<string>
|
||||
}
|
||||
) => Layer.effectDiscard(Effect.gen(function*() {
|
||||
const app = yield* ExpressApp.ExpressApp
|
||||
|
||||
app.use(yield* config.path,
|
||||
createExpressMiddleware({
|
||||
router: yield* TRPCAnyRouter,
|
||||
createContext: (yield* TRPCUnknownContextCreator).createExpressContext,
|
||||
})
|
||||
)
|
||||
}))
|
||||
@@ -1,4 +1,5 @@
|
||||
export * as TRPCBuilder from "./TRPCBuilder"
|
||||
export * as TRPCContext from "./TRPCContext"
|
||||
export * as TRPCContextCreator from "./TRPCContextCreator"
|
||||
export * as TRPCExpressRoute from "./TRPCExpressRoute"
|
||||
export * as TRPCRouter from "./TRPCRouter"
|
||||
|
||||
Reference in New Issue
Block a user