feat: extend app.request paramters (#1442)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* feat: extend app.request paramters * denoify
authored by hagishi · committed by GitHub · parent c3d9843 · Browse files · 3 files·+26 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+26 added−6 removed
- tests:+10 added−0 removed
- other:+16 added−6 removed
Provenance
- Commit
2a13b09- Tree
2f0cb14- Author
hagishi <fujiyama@kakumei.jp>- Committer
GitHub <noreply@github.com>- Parent
c3d9843
3 files changed+26 added−6 removed
modified:deno_dist/hono-base.ts+8 added-3 removed
372 unmodified lines373 fetch = (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => {374 return this.dispatch(request, executionCtx, Env, request.method)375 }376 377- request = (input: Request | string | URL, requestInit?: RequestInit) => {377+ request = (378+ input: Request | string | URL,379+ requestInit?: RequestInit,380+ Env?: E['Bindings'] | {},381+ executionCtx?: ExecutionContext382+ ) => {383 if (input instanceof Request) {384 if (requestInit !== undefined) {385 input = new Request(input, requestInit)386 }382- return this.fetch(input)387+ return this.fetch(input, Env, executionCtx)388 }389 input = input.toString()390 const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath('/', input)}`391 const req = new Request(path, requestInit)387- return this.fetch(req)392+ return this.fetch(req, Env, executionCtx)393 }394 395 fire = () => {396 // eslint-disable-next-line @typescript-eslint/ban-ts-comment8 unmodified linesmodified:src/hono-base.ts+8 added-3 removed
372 unmodified lines373 fetch = (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => {374 return this.dispatch(request, executionCtx, Env, request.method)375 }376 377- request = (input: Request | string | URL, requestInit?: RequestInit) => {377+ request = (378+ input: Request | string | URL,379+ requestInit?: RequestInit,380+ Env?: E['Bindings'] | {},381+ executionCtx?: ExecutionContext382+ ) => {383 if (input instanceof Request) {384 if (requestInit !== undefined) {385 input = new Request(input, requestInit)386 }382- return this.fetch(input)387+ return this.fetch(input, Env, executionCtx)388 }389 input = input.toString()390 const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath('/', input)}`391 const req = new Request(path, requestInit)387- return this.fetch(req)392+ return this.fetch(req, Env, executionCtx)393 }394 395 fire = () => {396 // eslint-disable-next-line @typescript-eslint/ban-ts-comment8 unmodified linesmodified:src/hono.test.ts+10 added
32 unmodified lines33 c.status(201)34 return c.html('<h1>Hono!!!</h1>')35 })36 37+ app.get('/hello-env', (c) => {38+ return c.json(c.env)39+ })40+41 it('GET http://localhost/hello is ok', async () => {42 const res = await app.request('http://localhost/hello')43 expect(res).not.toBeNull()44 expect(res.status).toBe(200)35 unmodified lines80 const res = await app.request('http://localhost/')81 expect(res).not.toBeNull()82 expect(res.status).toBe(404)83 })84+85+ it('GET /hello-env is ok', async () => {86+ const res = await app.request('/hello-env', undefined, { HELLO: 'world' })87+ expect(res.status).toBe(200)88+ expect(await res.json()).toEqual({ HELLO: 'world' })89+ })90 })91 92 describe('Register handlers without a path', () => {93 describe('No basePath', () => {2570 unmodified lines