diff --git a/deno_dist/client/types.ts b/deno_dist/client/types.ts index 13b5e4fb9..d5e25a262 100644 --- a/deno_dist/client/types.ts +++ b/deno_dist/client/types.ts @@ -2,9 +2,11 @@ import type { Hono } from '../hono.ts' import type { Schema } from '../types.ts' import type { RemoveBlankRecord } from '../utils/types.ts' +type HonoRequest = typeof Hono.prototype['request'] + export type ClientRequestOptions = { headers?: Record - fetch?: typeof fetch + fetch?: typeof fetch | HonoRequest } type ClientRequest = { diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index a21059f9e..61996784f 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -375,7 +375,7 @@ class Hono< } request = ( - input: Request | string | URL, + input: RequestInfo | URL, requestInit?: RequestInit, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 07d87d243..0880cbb08 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -470,3 +470,13 @@ describe('Use custom fetch method', () => { expect(res).toEqual(returnValue) }) }) + +describe('Use custom fetch (app.request) method', () => { + it('Should return Response from app request method', async () => { + const app = new Hono().get('/search', (c) => c.jsonT({ ok: true })) + type AppType = typeof app + const client = hc('', { fetch: app.request }) + const res = await client.search.$get() + expect(res.ok).toBe(true) + }) +}) diff --git a/src/client/types.ts b/src/client/types.ts index 34fb7df2e..83f4e3061 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -2,9 +2,11 @@ import type { Hono } from '../hono' import type { Schema } from '../types' import type { RemoveBlankRecord } from '../utils/types' +type HonoRequest = typeof Hono.prototype['request'] + export type ClientRequestOptions = { headers?: Record - fetch?: typeof fetch + fetch?: typeof fetch | HonoRequest } type ClientRequest = { diff --git a/src/hono-base.ts b/src/hono-base.ts index 359882bfa..64dd9d875 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -375,7 +375,7 @@ class Hono< } request = ( - input: Request | string | URL, + input: RequestInfo | URL, requestInit?: RequestInit, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext