-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
502 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
new Elysia() | ||
.macro({ | ||
auth(enabled: boolean) { | ||
return { | ||
async resolve() { | ||
return { | ||
user: 'saltyaom' | ||
} | ||
} | ||
} | ||
} | ||
import { Elysia, t } from '../src' | ||
|
||
const app = new Elysia() | ||
.onParse('custom', ({ contentType, request }) => { | ||
if (contentType.startsWith('application/x-elysia-1')) | ||
return { name: 'Eden' } | ||
}) | ||
.get('/', ({ user }) => {}, { | ||
auth: true | ||
.onParse('custom2', ({ contentType, request }) => { | ||
if (contentType.startsWith('application/x-elysia-2')) | ||
return { name: 'Pardofelis' } | ||
}) | ||
.post('/json', ({ body }) => body, { | ||
parse: ['custom'] | ||
}) | ||
|
||
const response = await Promise.all([ | ||
app | ||
.handle( | ||
new Request('http://localhost:3000/json', { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json' | ||
}, | ||
body: JSON.stringify({ name: 'Aru' }) | ||
}) | ||
) | ||
.then((x) => x.json()), | ||
app | ||
.handle( | ||
new Request('http://localhost:3000/json', { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/x-elysia-1' | ||
}, | ||
body: JSON.stringify({ name: 'Aru' }) | ||
}) | ||
) | ||
.then((x) => x.text()), | ||
app | ||
.handle( | ||
new Request('http://localhost:3000/json', { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/x-elysia-2' | ||
}, | ||
body: JSON.stringify({ name: 'Aru' }) | ||
}) | ||
) | ||
.then((x) => x.text()) | ||
]) | ||
|
||
console.log(response) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.