Skip to content

mount() produces incorrect URL path when Elysia instance has prefix option #1671

@notcome

Description

@notcome

What version of Elysia is running?

[email protected]

What platform is your computer?

Darwin 25.1.0 arm64 arm

What environment are you using?

Bun 1.3.6

Are you using dynamic mode?

No, default aot: true. Issue also reproduces with aot: false.

What steps can reproduce the bug?

import { describe, expect, it } from 'bun:test'
import { Elysia } from 'elysia'

describe('Mount with prefix', () => {
  it('mount without prefix - strips mount path', async () => {
    const app = new Elysia()
      .mount('/sdk/problems-domain', (request) => {
        return Response.json({ path: new URL(request.url).pathname })
      })

    const response = await app
      .handle(new Request('http://localhost/sdk/problems-domain/problems'))
      .then((x) => x.json())

    expect(response.path).toBe('/problems') // ✅ PASSES
  })

  it('mount with prefix - should strip both prefix and mount path', async () => {
    const sdkApp = new Elysia({ prefix: '/sdk' })
      .mount('/problems-domain', (request) => {
        return Response.json({ path: new URL(request.url).pathname })
      })

    const app = new Elysia().use(sdkApp)

    const response = await app
      .handle(new Request('http://localhost/sdk/problems-domain/problems'))
      .then((x) => x.json())

    expect(response.path).toBe('/problems') // ❌ FAILS
  })
})

What is the expected behavior?

When using mount() on an Elysia instance that has a prefix option, the mounted handler should receive the URL with the full prefix + mount path stripped.

For request to /sdk/problems-domain/problems:

  • Expected: handler receives path /problems

What do you see instead?

The handler receives /main/problems - a mysterious /main/ prefix appears from nowhere.

without prefix: { path: "/problems" }    ✅
with prefix:    { path: "/main/problems" } ❌

Additional information

  • The issue only occurs when combining prefix option with mount()
  • Using mount() without prefix works correctly
  • The /main/ string doesn't appear anywhere in my code

Have you tried removing the node_modules and bun.lockb?

Yes, issue persists with fresh install.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions