MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / createContext

Function createContext

packages/trpc/src/trpc.ts:34–60  ·  view source on GitHub ↗
({ req, res }: CreateFastifyContextOptions)

Source from the content-addressed store, hash-verified

32 });
33
34export async function createContext({ req, res }: CreateFastifyContextOptions) {
35 const cookies = (req as any).cookies as Record<string, string | undefined>;
36 const setCookie: ISetCookie = (key, value, options) => {
37 // @ts-ignore
38 res.setCookie(key, value, {
39 maxAge: options.maxAge,
40 signed: options.signed,
41 ...COOKIE_OPTIONS,
42 });
43 };
44
45 if (process.env.NODE_ENV !== 'production') {
46 await new Promise((res) =>
47 setTimeout(() => res(1), Math.min(Math.random() * 500, 200)),
48 );
49 }
50
51 return {
52 req,
53 res,
54 session: (req as any).session as SessionValidationResult,
55 // we do not get types for `setCookie` from fastify
56 // so define it here and be safe in routers
57 setCookie,
58 cookies,
59 };
60}
61export type Context = Awaited<ReturnType<typeof createContext>>;
62
63const t = initTRPC.context<Context>().create({

Callers 10

theme-provider.tsxFile · 0.85
replay-context.tsxFile · 0.85
context.tsxFile · 0.85
chat-runtime.tsxFile · 0.85
chat-context.tsxFile · 0.85
createChartTooltipFunction · 0.85
chart-context.tsxFile · 0.85
page-context.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected