Skip to content

Commit 33fc4a6

Browse files
authored
Use fallback for methods (#580)
1 parent aae4111 commit 33fc4a6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/integrations/sveltekit.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ With SvelteKit, you can run Elysia on server routes.
2020

2121
1. Create **src/routes/[...slugs]/+server.ts**.
2222
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
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.
2424

2525
```typescript
2626
// src/routes/[...slugs]/+server.ts
@@ -38,6 +38,8 @@ type RequestHandler = (v: { request: Request }) => Response | Promise<Response>
3838

3939
export const GET: RequestHandler = ({ request }) => app.handle(request)
4040
export const POST: RequestHandler = ({ request }) => app.handle(request)
41+
// or simply
42+
export const fallback: RequestHandler = ({ request }) => app.handle(request)
4143
```
4244

4345
You can treat the Elysia server as a normal SvelteKit server route.
@@ -65,8 +67,7 @@ const app = new Elysia({ prefix: '/api' }) // [!code ++]
6567

6668
type RequestHandler = (v: { request: Request }) => Response | Promise<Response>
6769

68-
export const GET: RequestHandler = ({ request }) => app.handle(request)
69-
export const POST: RequestHandler = ({ request }) => app.handle(request)
70+
export const fallback: RequestHandler = ({ request }) => app.handle(request)
7071
```
7172

7273
This will ensure that Elysia routing will work properly in any location you place it.

0 commit comments

Comments
 (0)