Skip to content
Myr

fix(app): `app.mount()` supports `/` (#1119)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(app): `app.mount()` supports `/` * chore: denoify

authored by Yusuke Wada · committed by GitHub · parent 0ffd795 · Browse files · 3 files+42 added−4 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+42 added−4 removed

  • tests:+36 added−2 removed
  • other:+6 added−2 removed

3 files+42 added−4 removed

modified:deno_dist/hono-base.ts+3 added-1 removed
203 unmodified lines
204 // eslint-disable-next-line @typescript-eslint/no-explicit-any205 applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>,206 optionHandler?: (c: Context) => unknown207 ): Hono<E, S, BasePath> {208 const pathPrefixLength = mergePath(this._basePath, path).length208 const mergedPath = mergePath(this._basePath, path)209 const pathPrefixLength = mergedPath === '/' ? 0 : mergedPath.length210211 const handler: MiddlewareHandler = async (c, next) => {212 let executionContext: ExecutionContext | undefined = undefined213 try {214 executionContext = c.executionCtx
150 unmodified lines
modified:src/hono-base.ts+3 added-1 removed
203 unmodified lines
204 // eslint-disable-next-line @typescript-eslint/no-explicit-any205 applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>,206 optionHandler?: (c: Context) => unknown207 ): Hono<E, S, BasePath> {208 const pathPrefixLength = mergePath(this._basePath, path).length208 const mergedPath = mergePath(this._basePath, path)209 const pathPrefixLength = mergedPath === '/' ? 0 : mergedPath.length210211 const handler: MiddlewareHandler = async (c, next) => {212 let executionContext: ExecutionContext | undefined = undefined213 try {214 executionContext = c.executionCtx
150 unmodified lines
modified:src/hono.test.ts+36 added-2 removed
1914 unmodified lines
1915describe('app.mount()', () => {1916 describe('Basic', () => {1917 const anotherApp = (req: Request, params: unknown) => {1918 const path = getPath(req)1919 console.log(`path in anotherApp: ${path}`)1919 if (path === '/') {1920 return new Response('AnotherApp')1921 }1922 if (path === '/hello') {
14 unmodified lines
1937 },1938 }1939 )1940 }1942 console.log(`before 404 ${req.url}`)1941 return new Response('Not Found from AnotherApp', {1942 status: 404,1943 })1944 }
117 unmodified lines
2062 },2063 })2064 })2065 })20662067 describe('Mount on `/`', () => {2068 const anotherApp = (req: Request, params: unknown) => {2069 const path = getPath(req)2070 if (path === '/') {2071 return new Response('AnotherApp')2072 }2073 if (path === '/hello') {2074 return new Response('Hello from AnotherApp')2075 }2076 if (path === '/good/night') {2077 return new Response('Good Night from AnotherApp')2078 }2079 return new Response('Not Found from AnotherApp', {2080 status: 404,2081 })2082 }20832084 const app = new Hono()2085 app.mount('/', anotherApp)20862087 it('Should return responses from AnotherApp - mount on `/`', async () => {2088 let res = await app.request('/')2089 expect(res.status).toBe(200)2090 expect(await res.text()).toBe('AnotherApp')2091 res = await app.request('/hello')2092 expect(res.status).toBe(200)2093 expect(await res.text()).toBe('Hello from AnotherApp')2094 res = await app.request('/good/night')2095 expect(res.status).toBe(200)2096 expect(await res.text()).toBe('Good Night from AnotherApp')2097 res = await app.request('/not-found')2098 expect(res.status).toBe(404)2099 expect(await res.text()).toBe('Not Found from AnotherApp')2100 })2101 })2102})21032104describe('Router Name', () => {2105 it('Should return the correct router name', async () => {
10 unmodified lines