|
1 | | -import { Elysia, t } from 'elysia' |
2 | | -import { ElysiaNodeContext, node } from '../src' |
| 1 | +import { Elysia } from 'elysia' |
| 2 | +import node from '../src' |
3 | 3 |
|
4 | | -const app = new Elysia({ |
| 4 | +export const elysiaApp = new Elysia({ |
5 | 5 | adapter: node() |
6 | 6 | }) |
7 | | - .onError(({ request }) => { |
8 | | - return |
9 | | - }) |
10 | | - .post( |
11 | | - '/', |
12 | | - ({ body }) => { |
13 | | - console.log({ body }) |
14 | | - |
15 | | - return 'OK' |
16 | | - }, |
17 | | - { |
18 | | - body: t.Object({ |
19 | | - test: t.String() |
20 | | - }) |
21 | | - } |
22 | | - ) |
23 | | - .listen(3000) |
24 | | - |
25 | | -// console.log(app._handle.toString()) |
26 | | -// console.log(app.routes[0].compile().toString()) |
27 | | -// console.log(app.handleError.toString()) |
| 7 | + // .onError(({ error }) => { |
| 8 | + // console.log(error) |
| 9 | + // }) |
| 10 | + .patch('/', () => { |
| 11 | + const form = new FormData() |
| 12 | + form.append('name', 'Sancho') |
| 13 | + form.append('alias', 'Don Quixote') |
28 | 14 |
|
29 | | -const main = async () => { |
30 | | - const res = await fetch('http://localhost:3000/', { |
31 | | - method: 'POST', |
32 | | - headers: { |
33 | | - 'Content-Type': 'application/json' |
34 | | - }, |
35 | | - body: JSON.stringify({ bad: '' }) |
| 15 | + return form |
36 | 16 | }) |
37 | 17 |
|
38 | | - console.log('status', res.status) |
| 18 | +export type ElysiaApp = typeof elysiaApp |
39 | 19 |
|
40 | | - // app.stop(true) |
41 | | -} |
| 20 | +elysiaApp.listen(3334) |
| 21 | +console.log('Server started at http://localhost:3334') |
42 | 22 |
|
43 | | -main() |
| 23 | +fetch('http://localhost:3334/', { method: 'PATCH' }) |
| 24 | + .then((x) => x.formData()) |
| 25 | + .then(console.log) |
0 commit comments