elysiajs / eden

Fully type-safe Elysia client
MIT License
147 stars 37 forks source link

[bug] prefixed group/guarded routes #103

Closed directormac closed 2 months ago

directormac commented 2 months ago

Hi i'm trying to group my routes in a manner like this.

export const auth = new Elysia({ prefix: 'auth' })
 .guard((app) =>
  app.model({...}).use(...)
  .post('/login', () => {'OK'})
  .post('signup', () => {'OK'})
);

The following resolves to this

const api = treaty<AppType>(PUBLIC_API_URL);

//api.auth does not have any methods as expected
api.authlogin.post()
api.authlogin.post()

Expected behavior

const api = treaty<AppType>(PUBLIC_API_URL);

//api.auth does not have any methods as expected
api.auth.login.post()
api.auth.login.post()
directormac commented 2 months ago

Fix was simple prefixed routes needs a trailing slash

export const auth = new Elysia({ prefix: 'auth/' })
 .guard((app) =>
  app.model({...}).use(...)
  .post('/login', () => {'OK'})
  .post('signup', () => {'OK'})
);