Skip to content

Commit

Permalink
#38
Browse files Browse the repository at this point in the history
- preset/bun: правки обработки событий рендера
  • Loading branch information
krutoo committed Feb 28, 2024
1 parent 875d3a9 commit 6e0f4f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/preset/bun/bun/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { toMilliseconds } from '../../../../utils';
import { ServerMiddleware } from '../../../server/types';
import { applyServerMiddleware } from '../../../server/utils';
import PromClient from 'prom-client';
import { RESPONSE_EVENT_TYPE } from '../../../isomorphic/constants';

export const BunProviders = {
configSource(): ConfigSource {
Expand Down Expand Up @@ -63,8 +64,8 @@ export const BunProviders = {
return router(
// маршруты с промежуточными слоями
...routes.map(([pathname, handler]) => {
const enhanced = enhance(handler);
return route(pathname, request => enhanced(request, { events: new EventTarget() }));
const enhancedHandler = enhance(handler);
return route(pathname, request => enhancedHandler(request, { events: new EventTarget() }));
}),

// @todo вместо routes обрабатывать pageRoutes с помощью route.get() из новой версии fetch-tools (для явности)
Expand Down Expand Up @@ -128,20 +129,21 @@ export const BunProviders = {

// @todo tracing

// метрики
async (request, next, context) => {
const responseStart = process.hrtime.bigint();
let renderStart = 0n;

context.events.addEventListener(
'render:start',
RESPONSE_EVENT_TYPE.renderStart,
() => {
renderStart = process.hrtime.bigint();
},
{ once: true },
);

context.events.addEventListener(
'render:finish',
RESPONSE_EVENT_TYPE.renderFinish,
() => {
const renderFinish = process.hrtime.bigint();

Expand Down

0 comments on commit 6e0f4f0

Please sign in to comment.