Skip to content

Register middleware after routing, routePath(c, -1) are error #4609

@seepine

Description

@seepine

What version of Hono are you using?

4.11.3

What runtime/platform is your app running on? (with version if possible)

Bun

What steps can reproduce the bug?

const app = new Hono()

app.use(async (c, next) => {
  console.log(`[middleware A] in`, c.req.path, routePath(c), routePath(c, -1))
  await next()
  console.log(`[middleware A] out`)
})

app.get('/health', (c) => {
  return c.json({
    status: 'ok',
  })
})

// Register middleware after `/health`
app.use(async (c, next) => {
  console.log(`[middleware B] in`, c.req.path, routePath(c), routePath(c, -1))
  await next()
  console.log(`[middleware B] out`)
})

const server = Bun.serve({
  port: process.env.PORT ?? 3000,
  fetch: app.fetch,
})

And got /*, whether routePath(c, -1) or routePath(c)

[middleware A] in /health /* /*
[middleware A] out

What is the expected behavior?

can got /health

What do you see instead?

got /*

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions