RPC server work
This commit is contained in:
12
packages/server/src/trpc/CreateTRPCContext.ts
Normal file
12
packages/server/src/trpc/CreateTRPCContext.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
||||
import { Context, Layer } from "effect"
|
||||
import type { TRPCContext } from "./TRPCContext"
|
||||
|
||||
|
||||
export class CreateTRPCContext extends Context.Tag("CreateTRPCContext")<CreateTRPCContext,
|
||||
(opts: CreateExpressContextOptions) => TRPCContext
|
||||
>() {}
|
||||
|
||||
export module CreateTRPCContext {
|
||||
export const Live = Layer.sync(CreateTRPCContext, () => ({ req }) => ({ req }))
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { initTRPC } from "@trpc/server"
|
||||
import { Context, Layer } from "effect"
|
||||
import type { TRPCContext } from "./context"
|
||||
import type { TRPCContext } from "./TRPCContext"
|
||||
|
||||
|
||||
const createTRPC = () => initTRPC.context<TRPCContext>().create()
|
||||
|
||||
6
packages/server/src/trpc/TRPCContext.ts
Normal file
6
packages/server/src/trpc/TRPCContext.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { Request } from "express"
|
||||
|
||||
|
||||
export interface TRPCContext {
|
||||
req: Request
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
||||
|
||||
|
||||
export const createTRPCContext = ({ req }: CreateExpressContextOptions) => ({ req })
|
||||
export type TRPCContext = Awaited<ReturnType<typeof createTRPCContext>>
|
||||
Reference in New Issue
Block a user