Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.x DRAFT #222

Merged
merged 18 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaned up example
  • Loading branch information
kwhitley committed Mar 14, 2024
commit a3b471b4d2abc459b747a069cbffa569cd681eba
35 changes: 35 additions & 0 deletions example/bun-autorouter-advanced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { text } from 'text'
import { json } from 'json'
import { AutoRouter } from '../src/AutoRouter'
import { error } from 'error'
import { IRequest } from 'IttyRouter'
import { withParams } from 'withParams'

const router = AutoRouter({
port: 3001,
missing: () => error(404, 'Are you sure about that?'),
format: () => {},
before: [
(r: any) => { r.date = new Date },
],
after: [
(r: Response, request: IRequest) =>
console.log(r.status, request.method, request.url, 'delivered in', Date.now() - request.date, 'ms from', request.date.toLocaleString()),
]
})

const childRouter = AutoRouter({
base: '/child',
missing: () => {},
})
.get('/:id', ({ id }) => [ Number(id), Number(id) / 2 ])

router
.get('/basic', () => new Response('Success!'))
.get('/text', () => 'Success!')
.get('/params/:foo', ({ foo }) => foo)
.get('/json', () => ({ foo: 'bar' }))
.get('/throw', (a) => a.b.c)
.get('/child/*', childRouter.fetch)

export default router
25 changes: 1 addition & 24 deletions example/bun-autorouter.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
import { text } from 'text'
import { json } from 'json'
import { AutoRouter } from '../src/AutoRouter'
import { error } from 'error'
import { IRequest } from 'IttyRouter'
import { withParams } from 'withParams'

const router = AutoRouter({
port: 3001,
missing: () => error(404, 'Are you sure about that?'),
format: () => {},
before: [
(r: any) => { r.date = new Date },
],
after: [
(r: Response, request: IRequest) =>
console.log(r.status, request.method, request.url, 'delivered in', Date.now() - request.date, 'ms from', request.date.toLocaleString()),
]
})

const childRouter = AutoRouter({
base: '/child',
missing: () => {},
})
.get('/:id', ({ id }) => [ Number(id), Number(id) / 2 ])
const router = AutoRouter({ port: 3001 })

router
.get('/basic', () => new Response('Success!'))
.get('/text', () => 'Success!')
.get('/params/:foo', ({ foo }) => foo)
.get('/json', () => ({ foo: 'bar' }))
.get('/throw', (a) => a.b.c)
.get('/child/*', childRouter.fetch)

export default router
Loading