diff --git a/mocks/app/routes/about/[name]/_middleware.ts b/mocks/app/routes/about/[name]/_middleware.ts index fea11d5..6cee1ae 100644 --- a/mocks/app/routes/about/[name]/_middleware.ts +++ b/mocks/app/routes/about/[name]/_middleware.ts @@ -3,7 +3,6 @@ import { createRoute } from '../../../../../src/factory' const addHeader = createMiddleware(async (c, next) => { await next() - console.log('fooo') c.res.headers.append('x-message', 'from middleware') }) diff --git a/mocks/app/routes/about/[name]/_renderer.tsx b/mocks/app/routes/about/[name]/_renderer.tsx index 50a9e22..2b1f667 100644 --- a/mocks/app/routes/about/[name]/_renderer.tsx +++ b/mocks/app/routes/about/[name]/_renderer.tsx @@ -8,7 +8,7 @@ export default jsxRenderer(({ children, title }) => {

About

-
{children}
+
{children}
) diff --git a/mocks/app/routes/about/[name]/hobbies/[hobby_name]/_middleware.ts b/mocks/app/routes/about/[name]/hobbies/[hobby_name]/_middleware.ts new file mode 100644 index 0000000..319036d --- /dev/null +++ b/mocks/app/routes/about/[name]/hobbies/[hobby_name]/_middleware.ts @@ -0,0 +1,9 @@ +import { createMiddleware } from 'hono/factory' +import { createRoute } from '../../../../../../../src/factory' + +const addHeader = createMiddleware(async (c, next) => { + await next() + c.res.headers.append('x-message-nested', 'from nested middleware') +}) + +export default createRoute(addHeader) diff --git a/mocks/app/routes/about/[name]/hobbies/[hobby_name]/index.tsx b/mocks/app/routes/about/[name]/hobbies/[hobby_name]/index.tsx new file mode 100644 index 0000000..3f445f5 --- /dev/null +++ b/mocks/app/routes/about/[name]/hobbies/[hobby_name]/index.tsx @@ -0,0 +1,10 @@ +import { createRoute } from '../../../../../../../src/factory' + +export default createRoute((c) => { + const { name, hobby_name } = c.req.param() + return c.render( +

+ {name}'s hobby is {hobby_name} +

+ ) +}) diff --git a/src/server/server.ts b/src/server/server.ts index 7121836..465592e 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -135,7 +135,7 @@ export const createApp = (options: BaseServerOptions): Hono }) const middlewareFile = Object.keys(MIDDLEWARE_FILE).find((x) => { - const replacedDir = dir.replace('[', '\\[').replace(']', '\\]') + const replacedDir = dir.replaceAll('[', '\\[').replace(']', '\\]') return new RegExp(replacedDir + '/_middleware.tsx?').test(x) }) diff --git a/test-integration/apps.test.ts b/test-integration/apps.test.ts index 6e117f2..1aaaed0 100644 --- a/test-integration/apps.test.ts +++ b/test-integration/apps.test.ts @@ -97,7 +97,7 @@ describe('Basic', () => { method: 'GET', }, ] - expect(app.routes).toHaveLength(routes.length * 2) + expect(app.routes).toHaveLength(46) expect(app.routes).toEqual( expect.arrayContaining( routes.map(({ path, method }) => { @@ -224,7 +224,18 @@ describe('With preserved', () => { expect(res.headers.get('x-message')).toBe('from middleware') // hono/jsx escape a single quote to ' expect(await res.text()).toBe( - 'me's address

About

me's address
' + 'me's address

About

me's address
' + ) + }) + + it('Should return 200 response - /about/me/hobbies/baseball', async () => { + const res = await app.request('/about/me/hobbies/baseball') + expect(res.status).toBe(200) + expect(res.headers.get('x-message')).toBe('from middleware') + expect(res.headers.get('x-message-nested')).toBe('from nested middleware') + // hono/jsx escape a single quote to ' + expect(await res.text()).toBe( + '

About

me's hobby is baseball

' ) })