-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* flowrouter is the new router and ittyrouter is the old router * further evolving the standard * added shared router tests for feature parity between IttyRouter and Rotuer * take that, linter! * cleaned up example * added AutoRouter test coverage * lint fix * types for before/after/onError * released v4.3.0-next.0 - releasing v4.3 as next to determine sizes * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * catch is a single handler * v4.3 DRAFT: rename after stage to finally (#225) * replaced after stage with finally * fixed potential bug in createResponse to prevent pollution if passed a Request as second param, like in v4.3 stages * createResponse simplified and safe against using as ResponseHandler
- Loading branch information
Showing
22 changed files
with
1,320 additions
and
959 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
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
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 }, | ||
], | ||
finally: [ | ||
(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 |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AutoRouter } from '../src/AutoRouter' | ||
|
||
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) | ||
|
||
export default router |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IRequest } from 'IttyRouter' | ||
import { Router } from '../src/Router' | ||
import { error } from '../src/error' | ||
import { json } from '../src/json' | ||
import { withParams } from '../src/withParams' | ||
|
||
const logger = (response: Response, request: IRequest) => { | ||
console.log(response.status, request.url, '@', new Date().toLocaleString()) | ||
} | ||
|
||
const router = Router({ | ||
port: 3001, | ||
before: [withParams], | ||
finally: [json, logger], | ||
catch: error, | ||
}) | ||
|
||
router | ||
.get('/basic', () => new Response('Success!')) | ||
.get('/text', () => 'Success!') | ||
.get('/params/:foo', ({ foo }) => foo) | ||
.get('/json', () => ({ foo: 'bar' })) | ||
.get('/throw', a => a.b.c) | ||
.all('*', () => error(404)) | ||
|
||
export default router |
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.