Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions packages/remix/src/server/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,9 @@ function makeWrappedRootLoader() {
};
}

function wrapRequestHandler(
function wrapRequestHandler<T extends ServerBuild | (() => ServerBuild | Promise<ServerBuild>)>(
origRequestHandler: RequestHandler,
build:
| ServerBuild
| { build: ServerBuild }
| (() => ServerBuild | { build: ServerBuild } | Promise<ServerBuild | { build: ServerBuild }>),
build: T,
options?: {
instrumentTracing?: boolean;
},
Expand All @@ -278,7 +275,7 @@ function wrapRequestHandler(

// check if the build is nested under `build` key
if ('build' in resolvedBuild) {
resolvedRoutes = createRoutes(resolvedBuild.build.routes);
resolvedRoutes = createRoutes((resolvedBuild.build as ServerBuild).routes);
} else {
resolvedRoutes = createRoutes(resolvedBuild.routes);
}
Expand Down Expand Up @@ -407,12 +404,12 @@ function instrumentBuildCallback(
/**
* Instruments `remix` ServerBuild for performance tracing and error tracking.
*/
export function instrumentBuild(
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>),
export function instrumentBuild<T extends ServerBuild | (() => ServerBuild | Promise<ServerBuild>)>(
build: T,
options?: {
instrumentTracing?: boolean;
},
): ServerBuild | (() => ServerBuild | Promise<ServerBuild>) {
): T {
if (typeof build === 'function') {
return function () {
const resolvedBuild = build();
Expand All @@ -424,19 +421,15 @@ export function instrumentBuild(
} else {
return instrumentBuildCallback(resolvedBuild, options);
}
};
} as T;
} else {
return instrumentBuildCallback(build, options);
return instrumentBuildCallback(build, options) as T;
}
}

export const makeWrappedCreateRequestHandler = (options?: { instrumentTracing?: boolean }) =>
function (origCreateRequestHandler: CreateRequestHandlerFunction): CreateRequestHandlerFunction {
return function (
this: unknown,
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>),
...args: unknown[]
): RequestHandler {
return function (this: unknown, build, ...args: unknown[]): RequestHandler {
const newBuild = instrumentBuild(build, options);
const requestHandler = origCreateRequestHandler.call(this, newBuild, ...args);

Expand Down
Loading