MCPcopy Create free account
hub / github.com/middleapi/orpc / init

Method init

packages/pino/src/handler-plugin.ts:65–196  ·  view source on GitHub ↗
(options: StandardHandlerOptions<T>)

Source from the content-addressed store, hash-verified

63 }
64
65 init(options: StandardHandlerOptions<T>): void {
66 options.rootInterceptors ??= []
67 options.interceptors ??= []
68 options.clientInterceptors ??= []
69
70 options.rootInterceptors.unshift(async (interceptorOptions) => {
71 const logger = (
72 (interceptorOptions.context as LoggerContext)[CONTEXT_LOGGER_SYMBOL] ?? this.logger
73 ).child({
74 rpc: { id: this.generateId(interceptorOptions), system: ORPC_NAME },
75 })
76
77 /**
78 * pino-http might have already set req info in bindings
79 */
80 if (!logger.bindings().req) {
81 logger.setBindings({
82 req: {
83 url: interceptorOptions.request.url,
84 method: interceptorOptions.request.method,
85 headers: {
86 'content-type': interceptorOptions.request.headers['content-type'],
87 'content-length': interceptorOptions.request.headers['content-length'],
88 'content-disposition': interceptorOptions.request.headers['content-disposition'],
89 },
90 },
91 })
92 }
93
94 if (this.logRequestAbort) {
95 const signal = interceptorOptions.request.signal
96
97 if (signal?.aborted) {
98 logger?.info(`request was aborted before handling (${String(signal.reason)})`)
99 }
100 else {
101 signal?.addEventListener('abort', () => {
102 logger?.info(`request is aborted (${String(signal.reason)})`)
103 }, { once: true })
104 }
105 }
106
107 try {
108 if (this.logRequestResponse) {
109 logger?.info('request received')
110 }
111
112 const result = await interceptorOptions.next({
113 ...interceptorOptions,
114 context: {
115 ...interceptorOptions.context,
116 [CONTEXT_LOGGER_SYMBOL]: logger,
117 },
118 })
119
120 if (this.logRequestResponse) {
121 if (result.matched) {
122 logger?.info({

Callers

nothing calls this directly

Calls 11

getLoggerFunction · 0.90
isAsyncIteratorObjectFunction · 0.90
overlayProxyFunction · 0.90
mapEventIteratorFunction · 0.90
childMethod · 0.80
bindingsMethod · 0.80
setBindingsMethod · 0.80
infoMethod · 0.65
errorMethod · 0.65
nextFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected