File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ With SvelteKit, you can run Elysia on server routes.
20
20
21
21
1 . Create ** src/routes/[ ...slugs] /+server.ts** .
22
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
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.
24
24
25
25
``` typescript
26
26
// src/routes/[...slugs]/+server.ts
@@ -38,6 +38,8 @@ type RequestHandler = (v: { request: Request }) => Response | Promise<Response>
38
38
39
39
export const GET: RequestHandler = ({ request }) => app .handle (request )
40
40
export const POST: RequestHandler = ({ request }) => app .handle (request )
41
+ // or simply
42
+ export const fallback: RequestHandler = ({ request }) => app .handle (request )
41
43
```
42
44
43
45
You can treat the Elysia server as a normal SvelteKit server route.
@@ -65,8 +67,7 @@ const app = new Elysia({ prefix: '/api' }) // [!code ++]
65
67
66
68
type RequestHandler = (v : { request: Request }) => Response | Promise <Response >
67
69
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 )
70
71
```
71
72
72
73
This will ensure that Elysia routing will work properly in any location you place it.
You can’t perform that action at this time.
0 commit comments