elysiajs / eden

Fully type-safe Elysia client
MIT License
158 stars 38 forks source link

Treaty and Dependency Injection #21

Open artecoop opened 1 year ago

artecoop commented 1 year ago

Hi! In order to use some feature of elysia like dependency injection (https://elysiajs.com/patterns/dependency-injection.html), I split the code into multiple file:

First, a state for the database

// setup.ts
export const setup = new Elysia({ name: 'setup' })
    .state('redis', redis)
// routes/auth.ts
import { Elysia } from 'elysia';

import { setup } from '../setup';

export const authRouter = new Elysia({prefix: "/auth"})
    .use(setup)
    .post('/login', async (context) => { ... })
    .post('/logout', async (context) => { ... }));
// routes/foo.ts
import { Elysia } from 'elysia';

import { setup } from '../setup';

export const fooRouter = new Elysia({prefix: "/foo"})
    .use(setup)
    .get('/', async (context) => { ... })
    .post('/manage', async (context) => { ... }));

and finally the main entry point for my app

// server.ts
import { Elysia } from 'elysia';

import { authRouter } from './routes/auth';
import { fooRouter } from './routes/foo';

const app = new Elysia()
    .use(authRouter)
    .use(fooRouter)
    .listen(6001);

export type App = typeof app;

console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`);

Working as expected, manually querying various endpoints.

When using Treaty, I get an empty elysia app on the client side

Screenshot 2023-09-20 at 10 09 36

Any idea where my code fails?

Thanks in advance!

G9000 commented 10 months ago

any workaround? was wondering why my eden type not working at all

fredericoo commented 8 months ago

Can’t replicate, seems to have been fixed in a newer releaase since the issue was posted?

CleanShot 2024-01-08 at 22 21 32@2x

pandrRe commented 7 months ago

This still does not work for me.

rubfergor commented 14 hours ago

This is still happening to me too on "elysia": "~1.1.17" and "@elysiajs/eden": "~1.1.3", with the same structure as @artecoop, which basically means I either create an humoungous index or I can't use Eden