Skip to content

Commit eeac88d

Browse files
committed
📘 doc: add tanstack start integration, bun fullstack dev server
1 parent 10c7579 commit eeac88d

File tree

16 files changed

+775
-63
lines changed

16 files changed

+775
-63
lines changed

docs/.vitepress/config.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ export default defineConfig({
283283
text: 'Extends Context',
284284
link: '/patterns/extends-context'
285285
},
286+
{
287+
text: 'Fullstack Dev Server',
288+
link: '/patterns/fullstack-dev-server'
289+
},
286290
{
287291
text: 'Macro',
288292
link: '/patterns/macro'
@@ -300,8 +304,12 @@ export default defineConfig({
300304
link: '/patterns/trace'
301305
},
302306
{
303-
text: 'Type',
304-
link: '/patterns/type'
307+
text: 'TypeBox (Elysia.t)',
308+
link: '/patterns/typebox'
309+
},
310+
{
311+
text: 'TypeScript',
312+
link: '/patterns/typescript'
305313
},
306314
{
307315
text: 'Unit Test',
@@ -493,6 +501,10 @@ export default defineConfig({
493501
text: 'SvelteKit',
494502
link: '/integrations/sveltekit'
495503
},
504+
{
505+
text: 'Tanstack Start',
506+
link: '/integrations/tanstack-start'
507+
},
496508
{
497509
text: 'Vercel',
498510
link: '/integrations/vercel'

docs/eden/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For a framework to have end-to-end type safety means you can connect client and
2525

2626
Elysia provides end-to-end type safety **without code generation** out of the box with an RPC-like connector, **Eden**
2727

28-
<video mute controls>
28+
<video mute controls style="aspect-ratio: 16/9;">
2929
<source src="/eden/eden-treaty.mp4" type="video/mp4" />
3030
Something went wrong trying to load video
3131
</video>

docs/eden/test.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ head:
1717
# Eden Test
1818
Using Eden, we can create an integration test with end-to-end type safety and auto-completion.
1919

20-
<video mute controls>
21-
<source src="/eden/eden-test.mp4" type="video/mp4" />
22-
Something went wrong trying to load video
23-
</video>
24-
25-
> Using Eden Treaty to create tests by [irvilerodrigues on Twitter](https://twitter.com/irvilerodrigues/status/1724836632300265926)
26-
2720
## Setup
2821
We can use [Bun test](https://bun.sh/guides/test/watch-mode) to create tests.
2922

docs/integrations/astro.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ We recommend running [Astro on Bun](https://docs.astro.build/en/recipes/bun) as
5858

5959
::: tip
6060
You can run Elysia server without running Astro on Bun thanks to WinterCG support.
61-
62-
However, some plugins like **Elysia Static** may not work if you are running Astro on Node.
6361
:::
6462

6563
With this approach, you can have co-location of both frontend and backend in a single repository and have End-to-end type-safety with Eden.

docs/integrations/expo.md

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,117 @@ head:
1818

1919
Starting from Expo SDK 50, and App Router v3, Expo allows us to create API route directly in an Expo app.
2020

21-
1. Create an Expo app if it doesn't exist with:
22-
```typescript
23-
bun create expo-app --template tabs
24-
```
21+
1. Create **app/[...slugs]+api.ts**
22+
2. Define an Elysia server
23+
3. Export **Elysia.fetch** name of HTTP methods you want to use
2524

26-
2. Create **app/[...slugs]+api.ts**
27-
3. In **[...slugs]+api.ts**, create or import an existing Elysia server
28-
4. Export the handler with the name of method you want to expose
25+
::: code-group
2926

30-
```typescript
31-
// app/[...slugs]+api.ts
27+
```typescript [app/[...slugs]+api.ts]
3228
import { Elysia, t } from 'elysia'
3329

3430
const app = new Elysia()
35-
.get('/', () => 'hello Next')
31+
.get('/', 'hello Expo')
3632
.post('/', ({ body }) => body, {
3733
body: t.Object({
3834
name: t.String()
3935
})
4036
})
4137

42-
export const GET = app.handle // [!code ++]
43-
export const POST = app.handle // [!code ++]
38+
export const GET = app.fetch // [!code ++]
39+
export const POST = app.fetch // [!code ++]
4440
```
4541

46-
Elysia will work normally as expected because of WinterCG compliance, however, some plugins like **Elysia Static** may not work if you are running Expo on Node.
42+
:::
4743

4844
You can treat the Elysia server as if normal Expo API route.
4945

50-
With this approach, you can have co-location of both frontend and backend in a single repository and have [End-to-end type safety with Eden](https://elysiajs.com/eden/overview.html) with both client-side and server action.
51-
52-
Please refer to [API route](https://docs.expo.dev/router/reference/api-routes/) for more information.
53-
5446
## Prefix
5547
If you place an Elysia server not in the root directory of the app router, you need to annotate the prefix to the Elysia server.
5648

5749
For example, if you place Elysia server in **app/api/[...slugs]+api.ts**, you need to annotate prefix as **/api** to Elysia server.
5850

59-
```typescript
60-
// app/api/[...slugs]+api.ts
51+
::: code-group
52+
53+
```typescript [app/api/[...slugs]+api.ts]
6154
import { Elysia, t } from 'elysia'
6255

63-
const app = new Elysia({ prefix: '/api' })
64-
.get('/', () => 'hi')
56+
const app = new Elysia({ prefix: '/api' }) // [!code ++]
57+
.get('/', 'Hello Expo')
6558
.post('/', ({ body }) => body, {
6659
body: t.Object({
6760
name: t.String()
6861
})
6962
})
7063

71-
export const GET = app.handle
72-
export const POST = app.handle
64+
export const GET = app.fetch
65+
export const POST = app.fetch
7366
```
7467

68+
:::
69+
7570
This will ensure that Elysia routing will work properly in any location you place it in.
7671

72+
## Eden
73+
74+
We can add [Eden](/eden/overview) for **end-to-end type safety** similar to tRPC.
75+
76+
1. Export `type` from the Elysia server
77+
78+
::: code-group
79+
80+
```typescript [app/[...slugs]+api.ts]
81+
import { Elysia } from 'elysia'
82+
83+
const app = new Elysia()
84+
.get('/', 'Hello Nextjs')
85+
.post(
86+
'/user',
87+
({ body }) => body,
88+
{
89+
body: treaty.schema('User', {
90+
name: 'string'
91+
})
92+
}
93+
)
94+
95+
export type app = typeof app // [!code ++]
96+
97+
export const GET = app.fetch
98+
export const POST = app.fetch
99+
```
100+
101+
:::
102+
103+
2. Create a Treaty client
104+
105+
::: code-group
106+
107+
```typescript [lib/eden.ts]
108+
import { treaty } from '@elysiajs/eden'
109+
import type { app } from '../app/[...slugs]+api'
110+
111+
export const api = treaty<app>('localhost:3000/api')
112+
```
113+
114+
:::
115+
116+
3. Use the client in both server and client components
117+
118+
::: code-group
119+
120+
```tsx [app/page.tsx]
121+
import { api } from '../lib/eden'
122+
123+
export default async function Page() {
124+
const message = await api.get()
125+
126+
return <h1>Hello, {message}</h1>
127+
}
128+
```
129+
130+
:::
131+
77132
## Deployment
78133
You can either directly use API route using Elysia and deploy as normal Elysia app normally if need or using [experimental Expo server runtime](https://docs.expo.dev/router/reference/api-routes/#deployment).
79134

docs/integrations/nextjs.md

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,120 @@ head:
1818

1919
With Next.js App Router, we can run Elysia on Next.js routes.
2020

21-
1. Create **api/[[...slugs]]/route.ts** inside app router
22-
2. In **route.ts**, create or import an existing Elysia server
23-
3. Export HTTP methods you want to use with `Elysia.handle`
21+
1. Create **app/api/[[...slugs]]/route.ts**
22+
2. define an Elysia server
23+
3. Export **Elysia.fetch** name of HTTP methods you want to use
24+
25+
::: code-group
2426

2527
```typescript [app/api/[[...slugs]]/route.ts]
26-
// app/api/[[...slugs]]/route.ts
2728
import { Elysia, t } from 'elysia'
2829

2930
const app = new Elysia({ prefix: '/api' })
30-
.get('/', () => 'hello Next')
31+
.get('/', 'Hello Nextjs')
3132
.post('/', ({ body }) => body, {
3233
body: t.Object({
3334
name: t.String()
3435
})
3536
})
3637

37-
export const GET = app.handle
38-
export const POST = app.handle
38+
export const GET = app.fetch // [!code ++]
39+
export const POST = app.fetch // [!code ++]
3940
```
4041

41-
Elysia will work normally as expected because of WinterCG compliance, however, some plugins like **Elysia Static** may not work if you are running Next.js on Node.
42+
:::
4243

43-
You can treat the Elysia server as a normal Next.js API route.
44+
Elysia will work normally as expected because of WinterCG compliance.
4445

45-
With this approach, you can have co-location of both frontend and backend in a single repository and have [End-to-end type safety with Eden](https://elysiajs.com/eden/overview.html) with both client-side and server action
46+
You can treat the Elysia server as a normal Next.js API route.
4647

47-
Please refer to [Next.js Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers#static-route-handlers) for more information.
48+
With this approach, you can have co-location of both frontend and backend in a single repository and have [End-to-end type safety with Eden](/eden/overview) with both client-side and server action
4849

4950
## Prefix
5051

5152
Because our Elysia server is not in the root directory of the app router, you need to annotate the prefix to the Elysia server.
5253

5354
For example, if you place Elysia server in **app/user/[[...slugs]]/route.ts**, you need to annotate prefix as **/user** to Elysia server.
5455

55-
```typescript
56-
// app/user/[[...slugs]]/route.ts
56+
::: code-group
57+
58+
```typescript [app/user/[[...slugs]]/route.ts]
5759
import { Elysia, t } from 'elysia'
5860

5961
export default new Elysia({ prefix: '/user' }) // [!code ++]
60-
.get('/', () => 'hi')
62+
.get('/', 'Hello Nextjs')
6163
.post('/', ({ body }) => body, {
6264
body: t.Object({
6365
name: t.String()
6466
})
6567
})
68+
69+
export const GET = app.fetch
70+
export const POST = app.fetch
6671
```
6772

73+
:::
74+
6875
This will ensure that Elysia routing will work properly in any location you place it.
76+
77+
## Eden
78+
79+
We can add [Eden](/eden/overview) for **end-to-end type safety** similar to tRPC.
80+
81+
1. Export `type` from the Elysia server
82+
83+
::: code-group
84+
85+
```typescript [app/api/[[...slugs]]/route.ts]
86+
import { Elysia } from 'elysia'
87+
88+
const app = new Elysia({ prefix: '/api' })
89+
.get('/', 'Hello Nextjs')
90+
.post(
91+
'/user',
92+
({ body }) => body,
93+
{
94+
body: treaty.schema('User', {
95+
name: 'string'
96+
})
97+
}
98+
)
99+
100+
export type app = typeof app // [!code ++]
101+
102+
export const GET = app.fetch
103+
export const POST = app.fetch
104+
```
105+
106+
:::
107+
108+
2. Create a Treaty client
109+
110+
::: code-group
111+
112+
```typescript [lib/eden.ts]
113+
import { treaty } from '@elysiajs/eden'
114+
import type { app } from '../app/api/[[...slugs]]/route'
115+
116+
export const api = treaty<app>('localhost:3000/api')
117+
```
118+
119+
:::
120+
121+
3. Use the client in both server and client components
122+
123+
::: code-group
124+
125+
```tsx [app/page.tsx]
126+
import { api } from '../lib/eden'
127+
128+
export default async function Page() {
129+
const message = await api.get()
130+
131+
return <h1>Hello, {message}</h1>
132+
}
133+
```
134+
135+
:::
136+
137+
Please refer to [Next.js Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers#static-route-handlers) for more information.

docs/integrations/sveltekit.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,30 @@ head:
1919
With SvelteKit, you can run Elysia on server routes.
2020

2121
1. Create **src/routes/[...slugs]/+server.ts**.
22-
2. In **+server.ts**, create or import an existing Elysia server
23-
3. Export the handler with the name of method you want to expose. You can also use `fallback` to have Elysia handle all methods.
22+
2. Define an Elysia server.
23+
3. Export a **fallback** function that calls `app.handle`.
2424

2525
```typescript
2626
// src/routes/[...slugs]/+server.ts
2727
import { Elysia, t } from 'elysia';
2828

2929
const app = new Elysia()
30-
.get('/', () => 'hello SvelteKit')
30+
.get('/', 'hello SvelteKit')
3131
.post('/', ({ body }) => body, {
3232
body: t.Object({
3333
name: t.String()
3434
})
3535
})
3636

37-
type RequestHandler = (v: { request: Request }) => Response | Promise<Response>
37+
interface WithRequest {
38+
request: Request
39+
}
3840

39-
export const GET: RequestHandler = ({ request }) => app.handle(request)
40-
export const POST: RequestHandler = ({ request }) => app.handle(request)
41-
// or simply
42-
export const fallback: RequestHandler = ({ request }) => app.handle(request)
41+
export const fallback = ({ request }: WithRequest) => app.handle(request) // [!code ++]
4342
```
4443

4544
You can treat the Elysia server as a normal SvelteKit server route.
4645

47-
With this approach, you can have co-location of both frontend and backend in a single repository and have [End-to-end type-safety with Eden](https://elysiajs.com/eden/overview.html) with both client-side and server action
48-
49-
Please refer to [SvelteKit Routing](https://kit.svelte.dev/docs/routing#server) for more information.
50-
5146
## Prefix
5247
If you place an Elysia server not in the root directory of the app router, you need to annotate the prefix to the Elysia server.
5348

@@ -71,3 +66,5 @@ export const fallback: RequestHandler = ({ request }) => app.handle(request)
7166
```
7267

7368
This will ensure that Elysia routing will work properly in any location you place it.
69+
70+
Please refer to [SvelteKit Routing](https://kit.svelte.dev/docs/routing#server) for more information.

0 commit comments

Comments
 (0)