elysiajs/elysia

Duplicate Routes and Incorrect Path Handling in Elysia Framework

Opened this issue · 0 comments

What version of Elysia is running?

1.1.26

What platform is your computer?

No response

What steps can reproduce the bug?

import { swagger } from '@elysiajs/swagger';
import { Elysia } from 'elysia';

const publicApi2 = new Elysia({
	name: 'public',
	prefix: '/',
	tags: ['Public API'],
}).get('/', () => 200);

const publicApi = new Elysia({
	name: 'public',
	prefix: '/',
	tags: ['Public API'],
})
	.get('/', () => 200)
	.use(publicApi2);

const app = new Elysia()
	.use(swagger({ path: '/docs', provider: 'swagger-ui' }))
	.use(publicApi);

console.log(app.routes.map(({hooks, ...route}) => (route)));

What is the expected behavior?

[
  {
    method: 'GET',
    path: '/',
    composed: [Function (anonymous)],
    handler: [Function (anonymous)]
  }
]

What do you see instead?

[
  {
    method: 'GET',
    path: '//',
    composed: [Function (anonymous)],
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: '///',
    composed: [Function (anonymous)],
    handler: [Function (anonymous)]
  }
]

Additional information

The issue seems to be related to how the prefix and nested routes are being handled.

The extra / in the path is likely causing the routes to be incorrectly registered.

Have you try removing the node_modules and bun.lockb and try again yet?

No response