MCPcopy
hub / github.com/msgbyte/tianji / createContext

Function createContext

src/server/trpc/trpc.ts:15–34  ·  view source on GitHub ↗
({ req }: CreateExpressContextOptions)

Source from the content-addressed store, hash-verified

13import { parse as languageParse } from 'accept-language-parser';
14
15export async function createContext({ req }: CreateExpressContextOptions) {
16 const authorization = req.headers['authorization'] ?? '';
17 const token = authorization.replace('Bearer ', '');
18 const timezone = req.headers['timezone']
19 ? String(req.headers['timezone'])
20 : 'utc';
21 const language =
22 get(languageParse(req.headers['accept-language']), [0, 'code']) ?? 'en';
23
24 let origin = '';
25 if (req.headers['origin']) {
26 origin = String(req.headers['origin']);
27 } else if (req.headers['x-forwarded-proto'] && req.headers['host']) {
28 origin = `${req.headers['x-forwarded-proto']}://${req.headers['host']}`;
29 } else if (req.headers['host']) {
30 origin = `${req.protocol}://${req.headers['host']}`;
31 }
32
33 return { token, timezone, language, req, origin };
34}
35
36type Context = Awaited<ReturnType<typeof createContext>>;
37const t = initTRPC.context<Context>().meta<OpenApiMeta>().create();

Callers 8

branch.tsxFile · 0.85
web-preview.tsxFile · 0.85
message.tsxFile · 0.85
context.tsxFile · 0.85
code-block.tsxFile · 0.85
reasoning.tsxFile · 0.85
insights.tsxFile · 0.85

Calls 2

getFunction · 0.85
replaceMethod · 0.65

Tested by

no test coverage detected