mirror of
https://github.com/honojs/hono.git
synced 2024-11-29 17:46:30 +01:00
feat: extend app.request paramters (#1442)
* feat: extend app.request paramters * denoify
This commit is contained in:
parent
c3d984353a
commit
2a13b095c3
@ -374,17 +374,22 @@ class Hono<
|
||||
return this.dispatch(request, executionCtx, Env, request.method)
|
||||
}
|
||||
|
||||
request = (input: Request | string | URL, requestInit?: RequestInit) => {
|
||||
request = (
|
||||
input: Request | string | URL,
|
||||
requestInit?: RequestInit,
|
||||
Env?: E['Bindings'] | {},
|
||||
executionCtx?: ExecutionContext
|
||||
) => {
|
||||
if (input instanceof Request) {
|
||||
if (requestInit !== undefined) {
|
||||
input = new Request(input, requestInit)
|
||||
}
|
||||
return this.fetch(input)
|
||||
return this.fetch(input, Env, executionCtx)
|
||||
}
|
||||
input = input.toString()
|
||||
const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath('/', input)}`
|
||||
const req = new Request(path, requestInit)
|
||||
return this.fetch(req)
|
||||
return this.fetch(req, Env, executionCtx)
|
||||
}
|
||||
|
||||
fire = () => {
|
||||
|
@ -374,17 +374,22 @@ class Hono<
|
||||
return this.dispatch(request, executionCtx, Env, request.method)
|
||||
}
|
||||
|
||||
request = (input: Request | string | URL, requestInit?: RequestInit) => {
|
||||
request = (
|
||||
input: Request | string | URL,
|
||||
requestInit?: RequestInit,
|
||||
Env?: E['Bindings'] | {},
|
||||
executionCtx?: ExecutionContext
|
||||
) => {
|
||||
if (input instanceof Request) {
|
||||
if (requestInit !== undefined) {
|
||||
input = new Request(input, requestInit)
|
||||
}
|
||||
return this.fetch(input)
|
||||
return this.fetch(input, Env, executionCtx)
|
||||
}
|
||||
input = input.toString()
|
||||
const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath('/', input)}`
|
||||
const req = new Request(path, requestInit)
|
||||
return this.fetch(req)
|
||||
return this.fetch(req, Env, executionCtx)
|
||||
}
|
||||
|
||||
fire = () => {
|
||||
|
@ -34,6 +34,10 @@ describe('GET Request', () => {
|
||||
return c.html('<h1>Hono!!!</h1>')
|
||||
})
|
||||
|
||||
app.get('/hello-env', (c) => {
|
||||
return c.json(c.env)
|
||||
})
|
||||
|
||||
it('GET http://localhost/hello is ok', async () => {
|
||||
const res = await app.request('http://localhost/hello')
|
||||
expect(res).not.toBeNull()
|
||||
@ -77,6 +81,12 @@ describe('GET Request', () => {
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
|
||||
it('GET /hello-env is ok', async () => {
|
||||
const res = await app.request('/hello-env', undefined, { HELLO: 'world' })
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({ HELLO: 'world' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('Register handlers without a path', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user