Skip to content
Myr

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

3 files+26 added−6 removed

modified:deno_dist/hono-base.ts+8 added-3 removed
372 unmodified lines
373 fetch = (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => {374 return this.dispatch(request, executionCtx, Env, request.method)375 }376377 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 }394395 fire = () => {396 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8 unmodified lines
modified:src/hono-base.ts+8 added-3 removed
372 unmodified lines
373 fetch = (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => {374 return this.dispatch(request, executionCtx, Env, request.method)375 }376377 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 }394395 fire = () => {396 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8 unmodified lines
modified:src/hono.test.ts+10 added
32 unmodified lines
33 c.status(201)34 return c.html('<h1>Hono!!!</h1>')35 })3637 app.get('/hello-env', (c) => {38 return c.json(c.env)39 })4041 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 lines
80 const res = await app.request('http://localhost/')81 expect(res).not.toBeNull()82 expect(res.status).toBe(404)83 })8485 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})9192describe('Register handlers without a path', () => {93 describe('No basePath', () => {
2570 unmodified lines